Regular Expression method
Copy Code code as follows:
function checkrate (input)
{
var re =/^[0-9]+.? [0-9]*$/; Determines whether a string is a number//judgment positive integer/^[1-9]+[0-9]*]*$/
if (!re.test (Input.rate.value))
{
Alert ("Please enter a number (for example: 0.02)");
Input.rate.focus ();
return false;
}
}
The following is a common function
Copy Code code as follows:
function Baseisnotnum (thenum)
{
Judge 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)
{
To determine whether an integer
Theint=basetrim (Theint);
if ((theint.length>1 && theint.substring (0,1) = = "0") | | Baseisnotnum (Theint)) {
return true;
}
return false;
}
function Baseisnotfloat (thefloat)
{
To determine if 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;