/**
* 用于校验金额,小数点后面允许为二位
* oObject 为控件名称,一般为text控件
* mess 为提示的信息,为字符串
* leng 为允许的最大数值
* isMill 值为true时提示信息为万元,否则为元
* 校验通过返回true,否则出现警告信息并返回false
*/
function checkMoneyNum(oObject,mess,leng,isMill)
{
var realLength = parseInt(leng); //如果为空,则通过校验
if(oObject.value == "")
return true; //校验是否是合法数字,只能输入数字和小数点.
if(!(/^[\d|.]*$/g.test(oObject.value)))
{
oObject.select();
alert("["+mess+"]只能含有数字和小数点!");
return false;
}
//校验钱币的格式
if(/\.{1}/.test(oObject.value))
{
if(/^(-?)(\d+)\.(\d{1,2})$/.test(oObject.value))
{
var valueOfNum = parseFloat(oObject.value);
if(valueOfNum <= realLength)
return true;
else
{
oObject.select();
alert("["+mess+"]不能超过"+realLength + (isMill == true ? "万元":"元") + "!");
return false;
}
}
else
{
oObject.select();
alert("["+mess+"]必须符合格式(###.##)或(###),请重新输入!");
return false;
}
}
else
{
var valueOfIntNum = parseInt(oObject.value);
if(valueOfIntNum <= realLength)
return true;
else
{
oObject.select();
alert("["+mess+"]不能超过"+realLength + (isMill == true ? "万元":"元") + "!");
return false;
}
}
}
* 用于校验金额,小数点后面允许为二位
* oObject 为控件名称,一般为text控件
* mess 为提示的信息,为字符串
* leng 为允许的最大数值
* isMill 值为true时提示信息为万元,否则为元
* 校验通过返回true,否则出现警告信息并返回false
*/
function checkMoneyNum(oObject,mess,leng,isMill)
{
var realLength = parseInt(leng); //如果为空,则通过校验
if(oObject.value == "")
return true; //校验是否是合法数字,只能输入数字和小数点.
if(!(/^[\d|.]*$/g.test(oObject.value)))
{
oObject.select();
alert("["+mess+"]只能含有数字和小数点!");
return false;
}
//校验钱币的格式
if(/\.{1}/.test(oObject.value))
{
if(/^(-?)(\d+)\.(\d{1,2})$/.test(oObject.value))
{
var valueOfNum = parseFloat(oObject.value);
if(valueOfNum <= realLength)
return true;
else
{
oObject.select();
alert("["+mess+"]不能超过"+realLength + (isMill == true ? "万元":"元") + "!");
return false;
}
}
else
{
oObject.select();
alert("["+mess+"]必须符合格式(###.##)或(###),请重新输入!");
return false;
}
}
else
{
var valueOfIntNum = parseInt(oObject.value);
if(valueOfIntNum <= realLength)
return true;
else
{
oObject.select();
alert("["+mess+"]不能超过"+realLength + (isMill == true ? "万元":"元") + "!");
return false;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货