日期:2014-05-16  浏览次数:20386 次

如何用javascript判断文本框输入的是否是数字?急~~~~~~~
谢谢~~~~~~~~~~

------解决方案--------------------
var reg = /[0-9]/;
alert (reg.test( "123131312131a ");


------解决方案--------------------
if(isNaN(document.stepForm.test.value)){
alert( "test域数字类型,请重表输入! ");
return;
}
------解决方案--------------------
<html>
<head>
<title> 验证函数 </title>
</head>
<body>
<script >
function regex()
{
var regex=/^\d+$/g;
var str = document.form1.name1.value;
var result = regex.test(str);
alert(result);
}
</script>
<form name=form1>
<input type=text name=name1 >
<input type=button onClick= "regex() " value= "test " >
</form>
</body>
</html>