jQuery检查值是否为数字 [英] Jquery check if value is numeric

查看:169
本文介绍了jQuery检查值是否为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我只有一个要确保是数字的值.

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

推荐答案

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

Sure, use jQuery's isNumeric() function.

$.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

这篇关于jQuery检查值是否为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆