正则表达式验证小数是否非法
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>正则表达式验证小数 </TITLE>
</HEAD>
<BODY>
<script language="JavaScript" type="text/javascript">
function checkNum(obj)
{
var re = /^-?[1-9]*(\.\d*)?$|^-?d^(\.\d*)?$/;
if (!re.test(obj.value))
{
if(isNaN(obj.value)){
alert("非法数字");
obj.value="";
obj.focus();
return false;
}
}
}
</script>
<input name="rate" type="text"onkeyup="checkNum(this)" />
</BODY>
</HTML>