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;

}

posted @ 2020-03-28 15:44  15688611895  阅读(1516)  评论(0编辑  收藏  举报