js验证是否是数字(包括正整数,0,负整数,小数)
<script language="JavaScript" type="text/javascript">
function checkNum(obj)
{
var re = /^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/;
if (!re.test(obj.value))
{
alert("非法数字");
obj.value="";
return false;
}
}
</script><input name="rate" type="text" onblur="checkNum(this)" />