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

JavaScript用正则表达式怎样验证只能为数字
我现在需要验证一个文本框中的数字只能为数字,碰到了点小问题,请大家帮助一下,程序如下:
<?php  
include   "filefunction.php ";
?>
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 无标题文档 </title>
<SCRIPT   LANGUAGE= "JavaScript ">
function   check(num){
if(num   ==   " "){
alert( "修改后的大小必须填写 ");
return   false;
}
                  //下面开始验证只能为数字

}
</SCRIPT>
</head>

<body>
<p> 原附件大小: <?php   echo   readFileByte();?> <br>
    修改为
        <FORM   METHOD=POST   ACTION= "updatefilesize.php ">
<input   type= "text "   id= "updatefilesizetext ">
<input   type= "submit "   name= "Submit "   value= "修改 "   onClick= "return   check(document.getElementById( 'updatefilesizetext ').value); ">
        </FORM>
    <br>
</p>
</body>
</html>
请大家帮助一下.

------解决方案--------------------
javascript有一个函数
if(!isNaN(num)){
//数字
}
else{
//非数字
}
------解决方案--------------------
var reg = RegExp( '/^\d+$ ');
reg.test(); 返回为true或false;


-----------------------------------------------
msn:bdbox@hotmail.com
请给我一个与您交流的机会