js验证小数类型(浮点数)和整数类型
//参数19
if (IsHaveRole("IE")) {
return "<input id='Tpm_Target_Machine_Ct" + row.ID + "' type='text' class='haverole' onchange='isfloat(this)' value='" + (row.TPM_TARGET_MACHINE_CT) + "' />";
}
else {
return "<input id='Tpm_Target_Machine_Ct" + row.ID + "' type='text' disabled='disabled' class='notrole' onchange='isfloat(this)' value='" + (row.TPM_TARGET_MACHINE_CT) + "' />";
}
/**
只能输入数字和小数点
**/
function isfloat(obj) {
var oNum = obj.value;
if (!oNum) return false;
var strP = /^\d+(\.\d+)?$/;
if (!strP.test(oNum))
{
obj.value = "";
return false
};
try {
if (parseFloat(oNum) != oNum)
{
obj.value = "";
return false
};
} catch (ex) {
obj.value = "";
return false;
}
return true;
}
/**验证正整数**/
function isNumber(obj) {
var oNum = obj.value;
if (!oNum)
{
obj.value = "";
return false;
}
var strP = /^\d+$/; //正整数
if (!strP.test(oNum))
{
obj.value = "";
return false;
}
return true;
}