How to check if HTML input textbox is below a certain number using javascript?
I want to validate an input box using javascript to prevent users from entering above a certain number. I have alr开发者_Go百科eady done the validation for numbers. How do I prevent users from entering above a certain number? For example, users cannot enter more than 24.
I have tried onkeydown="return (this.value<25)"
HTML
<input type="text" size="2" maxlength="2" onkeydown="return ( event.ctrlKey || event.altKey
|| (47<event.keyCode && event.keyCode<58 && event.shiftKey==false)
|| (95<event.keyCode && event.keyCode<106)
|| (event.keyCode==8) || (event.keyCode==9)
|| (event.keyCode>34 && event.keyCode<40)
|| (event.keyCode==46)
|| (parseInt(this.value, 10)<25))">
Be sure to use radix:
return (parseInt(this.value, 10)<25)
精彩评论