使用 jQuery 验证器确定输入的值不是数字
我的问题很简单,但我找不到同样简单的解决方案。我有一个通过 jQuery 验证插件验证的文本字段,我想确保输入的值不是数字。最简单的方法是什么? 提前致谢! :)
My problem is very simple, but I can't find an equally simple solution. I have a text field that is validated via the jQuery validation plugin, and I want to make sure that the value entered is NOT a number. What is the simplest way to do so?
Thanks in advance! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
我还没有使用过 jQuery 验证器,但我想你可以提供自己的验证函数。
您可以这样做:
编辑:显然,
isNaN
也接受字符串,因此isNaN(value)
就足够了。如果你想确保输入不包含任何数字(这与输入不是数字不同),那么你必须使用正则表达式:
PS:无需 jQuery 也能工作;)
I didn't work with jQuery validator yet, but I guess you can provide your own validation function.
You could do:
Edit: Apparently,
isNaN
accepts a string too, soisNaN(value)
suffices.If you want to ensure that the input does not contain any digit (which is different from the input not being a number), then you would have to use regular expressions:
P.S.: Also works without jQuery ;)