用js脚本来写最好 因为php要到服务器端难证在form中添加 onclick="return checknumeric();"<script language="vbscript">
'===ZJ 校验函数===
'判断是否是数字
function checknumeric(obj)
if (obj.value <> "-" and obj.value <> "." and not Isnumeric(obj.value) and window.event.keycode<>9 and obj.value<>"" ) then
alert("请输入数字!")
obj.value=""
obj.focus
end if
end function</script>

解决方案 »

  1.   

    function fucCheckNUM(NUM)
    {
            var i,j,strTemp;
            strTemp="0123456789";
            if ( NUM.length== 0)
                    return 0
            for (i=0;i<NUM.length;i++)
            {
                    j=strTemp.indexOf(NUM.charAt(i));
                    if (j==-1)
                    {
                    //说明有字符不是数字
                            return 0;
                    }
            }
            //说明是数字
            return 1;
    }
    我这里有判断数字型的函数,但是,我怎么判断数组里的元素的类型?
      

  2.   

    这样写,仔细看看
    <script language="javascript">function IsDigit(cCheck)
    {
       return (('0'<=cCheck) && (cCheck<='9'));
    }
    function checkInput()
    {
      for(i=0;i<10;i++)
      {
         tmps1= document.form1.ss1[i].value;
         if (tmps1 == "")
     {
            alert("第"+i+"个输入框不能为空!");
        document.form1.ss1[i].focus();
        return false;
     }
     for (nIndex=0; nIndex<tmps1.length; nIndex++)
         {
          cCheck = tmps1.charAt(nIndex);
          if(!IsDigit(cCheck))
          {
    alert("第"+i+"个输入框必须是数字");
    document.form1.ss1[i].focus();
    return false;
          }
        }
      }
    }
    </script>
    <form name="form1" action="tt.php" method="post" onsubmit="return checkInput();">
    <?
    for ($i=0;$i<10;$i++)
    {
    ?>
    <input type=text name=sl[<?echo $i;?>] id=ss1  size=15 > <?
    }
    ?>
    <input type=submit name="ok" value="ok">
    </form>