Js verification is a summary of numbers. If you need a friend, you can refer to js verification to see if it is a number, the simplest method:
Use of the isNaN function:
Function checknum (){
If (isNaN (frm. num. value )){
Alert ("enter a number ");
Frm. num. focus ();
Return false;
}
}
The most complete and accurate method: (regular expression)
1)
"^ \ 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
2)
Var r =/^ \ +? [1-9] [0-9] * $/; // positive integer
R. test (str );
The most intuitive method: