In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces jquery how to judge whether there is a number of related knowledge, content detailed and easy to understand, simple and fast operation, with a certain reference value, I believe that everyone will read this jquery how to judge whether there are digital articles will be harvested, let's take a look at it.
In jquery, we can use the following methods to determine whether a variable is a number:
1、$.isNumeric();
jQuery is a built-in function used to determine whether it is a number. If $.isNumeric() is used to determine whether it is a number, some special characters will be treated as octal or decimal numbers, and it will be determined to be true, such as:(Related courses recommended: jQuery tutorial)$.isNumeric(0xFF); //true
$.isNumeric("0xFF"); //true$.isNumeric(3.13); //true
$.isNumeric("3.13"); //true
$.isNumeric(-3.13); //true
$.isNumeric("-3.13"); //true
$.isNumeric("03.13"); //true
$.isNumeric(01); //true
$.isNumeric(001); //true
$.isNumeric(+3.13); //true
$.isNumeric(0xFF); //true
$.isNumeric("0xFF"); //true
$.isNumeric(true); //false
$.isNumeric(NaN); //false
2、isNaN();
js is a function used to determine whether it is a number, it means "not a number", that is,"determine whether it is not a number, if it is not a number, it is true, if it is a number, it is false", its disadvantage is that some variables with empty values, such as null, spaces, etc., will turn them into "0" as a number to deal with: var val=$("#test").val();
var ival=parseInt(val);//if val is a number of character type convert to int if not ival is NaN
alert(typeof(ival));
if(! isNaN(ival)){
alert(val +"is a number");
} else{
alert(val +"not a number");
}
Description: isNaN() function returns false if the passed parameter is a number, otherwise returns true
3. Use regular expressions to judge
Common regular: "^\\d+$" //Non-negative integer (positive integer + 0)
"^[0-9]*[1-9][0-9]*$" //positive integer
"^((-\\d+)|(0+))$" //Non-positive integer (negative integer + 0)
"^-[0-9]*[1-9][0-9]*$" //negative integer
"^-?\\ d+$" //integer
"^\\d+(" //non-negative floating point number (positive floating point number + 0)
"^(([0-9]+\\. [0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\. [0-9]+)|([0-9]*[1-9][0-9]*))$" //positive floating point number
"^((-\\d+(" //Non-positive floating point number (negative floating point number + 0)
"^(-(([0-9]+\\. [0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\. [0-9]+)|([0-9]*[1-9][0-9]*)))$" //negative floating point number
"^(-?\\ d+)(" //floating point number
Example: var r=/^\+? [1-9][0-9]*$/; //Determine whether it is a positive integer
r.test(str);
Or: function isNumber(value) { //Verify whether it is a number
var patrn=/^(-)?\ d+(\.\ d+)?$/;
if (patrn.exec(value)==null || value=="") {
return false
} else {
return true
}
}
About "jquery how to judge whether there are numbers" The content of this article is introduced here, thank you for reading! I believe everyone has a certain understanding of the knowledge of "how jquery judges whether there are numbers." If you still want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.