Such a check has met a lot before, but each time is resolved on the end, no record down, and then the next encounter will spend a lot of time to write. Things need to accumulate, now special record down, hope that this kind of work no longer repeat too much, also share with everybody.
Copy Code code as follows:
<!---
================================================================================
Function Summary: Check whether the specified string is a valid number
As a person: Peter Jin
As own: 2010-04-23
================================================================================
--->
<cfoutput>
<script type= "Text/javascript" >
<!--
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;
}
function Basetrim (str)
{
Remove Space
Lidx=0;ridx=str.length;
if (basetrim.arguments.length==2)
Act=basetrim.arguments[1].tolowercase ();
Else
Act= "All";
for (Var i=0;i<str.length;i++) {
Thelstr=str.substring (lidx,lidx+1);
Therstr=str.substring (ridx,ridx-1);
if ((act== "All" | | act== "left") && thelstr== "") {
lidx++;
}
if ((act== "All" | | act== "right") && therstr== "") {
ridx--;
}
}
Str=str.slice (LIDX,RIDX);
return str;
}
-->
</script>
</cfoutput>