JS checks whether it is a number, whether it is an integer, and whether it is a floating point number
Regular Expression Method
Function checkrate (input)
{
VaR Re =/^ [0-9] + .? [0-9] * $/; // determines whether the string is a number. // determines a positive integer./^ [1-9] + [0-9] * $/
If (! Re. Test (input. rate. Value ))
{
Alert ("enter a number (for example, 0.02 )");
Input. rate. Focus ();
Return false;
}
}
The following describes how to write common functions.
Function baseisnotnum (thenum)
{
// Determine whether it is a number
If (basetrim (thenum) = "")
Return true;
For (VAR I = 0; I <thenum. length; I ++ ){
Onenum = thenum. substring (I, I + 1 );
If (onenum <"0" | onenum> "9 ")
Return true;
}
Return false;
}
Function baseisnotint (theint)
{
// Judge whether it is an integer
Theint = basetrim (theint );
If (theint. length> 1 & theint. substring (0, 1) = "0") | baseisnotnum (theint )){
Return true;
}
Return false;
}
Function baseisnotfloat (thefloat)
{
// Determine whether it is a floating point number
Len = thefloat. length;
Dotnum = 0;
If (LEN = 0)
Return true;
For (VAR I = 0; I <Len; I ++ ){
Onenum = thefloat. substring (I, I + 1 );
If (onenum = ".")
Dotnum ++;
If (onenum <"0" | onenum> "9") & onenum! = ".") | Dotnum> 1)
Return true;
}
If (LEN> 1 & thefloat. substring (0, 1) = "0 "){
If (thefloat. substring (1, 2 )! = ".")
Return true;
}
Return false;
}