Home > Article > Web Front-end > What is the method for jquery to determine whether it is a number?
How jquery determines whether it is a number: You can use the isNumeric method to determine, such as [$.isNumeric(0xFF);]. When using this method for judgment, some special characters will be treated as octal or hexadecimal numbers.
The operating environment of this tutorial: windows7 system, jquery3.2.1 version. This method is suitable for all brands of computers.
(Learning video sharing: javascript video tutorial)
1.$.isNumeric();
The built-in one in jquery is used to determine whether is a function of numbers. If you use $.isNumeric() to determine whether it is a number, some special characters will be treated as octal or hexadecimal numbers and will be judged as true.
$.isNumeric(0xFF); //true $.isNumeric("0xFF"); //true
2. isNaN();
A function in js 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 will be true, if it is a number, it will be false." Its disadvantage is that some variables with empty values, such as null, spaces, etc., will convert them to "0" and treat them as numbers:
isNaN("abc");//true isNaN(null);//false
3. Number();
The Number() function is actually used in js to convert a string into a number, but it can also be used by us to determine whether it is a number. If it is not a number, the value "NaN" will be returned, but like isNaN() above, if the value is null or empty, a 0 will be returned:
Number("aijquery.cn");//NaN Number(null);//0
Related recommendations: js tutorial
The above is the detailed content of What is the method for jquery to determine whether it is a number?. For more information, please follow other related articles on the PHP Chinese website!