复制代码 代码如下:
function checkRate(input)
{
var re = /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字 //判断正整数 /^[1-9]+[0-9]*]*$/
if (!re.test(input.rate.value))
{
alert("请输入数字(例:0.02)");
input.rate.focus();
return false;
}
}
下面为普通函数写法
复制代码 代码如下:
function baseisNotNum(theNum)
{
//判断是否为数字
if (basetrim(theNum)=="")
return true;
for(var i=0;i
if (oneNum<"0" || oneNum>"9")
return true;
}
return false;
}
function baseisNotInt(theInt)
{
//判断是否为整数
theInt=basetrim(theInt);
if ((theInt.length>1 && theInt.substring(0,1)=="0") || baseisNotNum(theInt)){
return true;
}
return false;
}
function baseisNotFloat(theFloat)
{
//判断是否为浮点数
len=theFloat.length;
dotNum=0;
if (len==0)
return true;
for(var i=0;i
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;



