Jquery 检查值是否为数字

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14464213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 13:35:58  来源:igfitidea点击:

Jquery check if value is numeric

jquerynumeric

提问by SoftwareSavant

I was wondering if anybody had a quick and dirty jquery method that will check if a value is numeric or not? I was thinking about using a regex type method to check the value, if not do not submit the form. I was using jquery validation, but I am running into issues just loading jquery validation.

我想知道是否有人有一个快速而肮脏的 jquery 方法来检查值是否为数字?我正在考虑使用正则表达式类型的方法来检查值,如果没有就不要提交表单。我正在使用 jquery 验证,但我在加载 jquery 验证时遇到了问题。

I just have one value that I want to make sure is numeric.

我只有一个值,我想确保它是数字。

回答by j08691

Sure, use jQuery's isNumeric()function.

当然,使用 jQuery 的isNumeric()函数。

$.isNumeric("-10"); ?// true
$.isNumeric(16); ? ? // true
$.isNumeric(0xFF); ? // true
$.isNumeric("0xFF"); // true
$.isNumeric("8e5"); ?// true (exponential notation string)
$.isNumeric(3.1415); // true
$.isNumeric(+10); ? ?// true
$.isNumeric(0144); ? // true (octal integer literal)
$.isNumeric(""); ? ? // false
$.isNumeric({}); ? ? // false (empty object)
$.isNumeric(NaN); ? ?// false
$.isNumeric(null); ? // false
$.isNumeric(true); ? // false
$.isNumeric(Infinity); // false
$.isNumeric(undefined); // false