<!--看看这个-->
<body>
<script language="JavaScript">
function checkNum(this_obj)
{
var s,re;
s=this_obj.inputnum.value;
if (s=='')
{
window.alert('请输入数字');
return false;
}
re=/^[\-]\d+/;
if (s.search(re)!=-1)
{
window.alert('请输入正数');
return false;
}
re=/[^\d\.]/;
if (s.search(re)!=-1)
{
window.alert('含有非法数字');
return false;
}
re=/^\d+\.\d{3,}/;
if (s.search(re)!=-1)
{
window.alert('小数点后最多只能两位');
return false;
}
return true;
}
</script>
<form method="POST" action="dosubmit.php" onsubmit="return checkNum(this)">
输入数字<input name="inputnum" type="text" size="16" value="">
<input type="submit" value="检查后提交">
</form>
</body>

解决方案 »

  1.   

    <html>
    <input id=pp type=text value=22.00>
    <input type=button onclick="aa();">
    <script>
    function aa()
    {
    if(pp.value.search(/[0-9]{2}.[0-9]{2}/)==0) 
       alert('ok')
    else 
       alert('input again');
    }</script>
    </html>
      

  2.   

    <html>
    <input id=pp type=text value=22.00>
    <input type=button onclick="aa();">
    <script>
    function aa()
    {
    if(pp.value.search(/[0-9]+.[0-9]{2}/)==0) 
       alert('ok')
    else 
       alert('input again');
    }</script>
    </html>