<input value=123 id=iecn><input type=button value=test onclick=checkNum(iecn.value)>
<script language=javascript>
function checkNum(str)
{
var re=/^\d+$/;
if(re.test(str))
alert("正确");
else
alert("错误")
}
</script>
<script language=javascript>
function checkNum(str)
{
var re=/^\d+$/;
if(re.test(str))
alert("正确");
else
alert("错误")
}
</script>
{
s += "";
if (!/^(\+|-)?\d+(\.\d+)?$/.test(s)){
alert("不是数字");
return false;
}
}
Determines whether a value is the reserved value NaN (not a number).
Syntax
isNaN(numvalue)
The numvalue argument is the value to be tested against NaN. Res
The isNaN function returns true if the value is NaN, and false otherwise. You typically use this function to test return values from the parseInt and parseFloat methods.
Alternatively, a variable could be compared to itself. If it compares as unequal, it is NaN. This is because NaN is the only value that is not equal to itself.
{
if (/^\d+(\.\d+)?$/.test(s)){
return true;
}
else {
return false;
}
}
{
return !isNaN(exp);
}