There are two ways to achieve this.
Let me start with the wrong way you should avoid. Don't try to use the same idea as filtering the input. I could easily create some JavaScript to filter input the way allowing only 1 to 24 or 0 to 24, whatever you want, but it will highly confuse the user. Imagine the user enters 23 and wants to change it to 21. The user can delete '3' and enter '1'. But she/he might want to add '1' first to get '231' to delete '3' later. You filter will prevent it leaving the user without any reasonable feedback on what to do. Don't try to introduce too complex filtering!
Instead, if you really want to stay with text input, you can use combination of filtering of characters on input, which you already achieved quite well, with
validation. Don't perform validation too early; do it only when the data input by the user is about to be used. Give a user clear feedback on the valid input, such as "The value of {0} must be {1} to {2}", something like that.
I would use much simpler approach though. If you expect only 24 valid values or so, I would simply uses a combo box with all values pre-entered. The user will only select one of them. See
http://www.asp.net/web-forms/tutorials/ajax-control-toolkit/combobox/how-do-i-use-the-combobox-control-cs[
^].
—SA