admin管理员组文章数量:1415684
I'm building a shopping cart and I would like to use a JavaScript function to validate user input when entering the quantity value in the quantity text input. I would like to allow the entering of integer values only (no floats, no other characters).
I know that I can apply this function using onKeyUp event and also I found isNaN() function, but it returns true even for floats (which is not ok).
Can you guys help me out with this one?
Thanks.
I'm building a shopping cart and I would like to use a JavaScript function to validate user input when entering the quantity value in the quantity text input. I would like to allow the entering of integer values only (no floats, no other characters).
I know that I can apply this function using onKeyUp event and also I found isNaN() function, but it returns true even for floats (which is not ok).
Can you guys help me out with this one?
Thanks.
Share Improve this question asked Jun 6, 2010 at 20:07 PsychePsyche 8,78322 gold badges71 silver badges86 bronze badges 3- 1 there is a nice jQuery plugin for this: digitalbush./projects/masked-input-plugin – meo Commented Jun 6, 2010 at 20:11
- Don't forget to validate on the server side, too. It's very easy to stop JavaScript outputting 'irritating' messages like “Hey you! You're supposed to only input numbers here!”. – Marcel Korpel Commented Jun 6, 2010 at 21:03
- @meo, pretty nice indeed. Thanks. – Psyche Commented Jun 6, 2010 at 22:28
1 Answer
Reset to default 6You can always check with parseInt:
if (number == parseInt(number))
本文标签: JavaScript function to validate an integer valueStack Overflow
版权声明:本文标题:JavaScript function to validate an integer value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745196911a2647185.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论