开发者

How to check if HTML input textbox is below a certain number using javascript?

开发者 https://www.devze.com 2023-03-23 13:24 出处:网络
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 enterin

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消