要求:小数位可有可无,最多两位小数,必须大于零

解决方案 »

  1.   


    /^\d+(?:.\d{1,2})?$/.test(12)
      

  2.   


    /^\d+(?:\.\d{1,2})?$/.test('12.12')/上面写错了.不好意思
      

  3.   

    function checkNumber(value){

    var re = /^\d+(?:\.\d{1,2})?$/;
    if(!re.test(value))  
    return false ;
    else
    return true ;
    }
    我这样写,哪里写错了吗?怎么还是不可以呢?
      

  4.   

    (^[1-9]\d+(?:\.\d{1,2})?$)|(^0.\d{0,1}[1-9]$)不过0.10的情况没通过,再想想吧...
      

  5.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head>
    <script type="text/javascript">
    function check()
    {
    var a = document.getElementById('num').value;
    var v =/^0{1}([.]\d{1,2})?$|^[1-9]\d*([.]{1}[0-9]{1,2})?$/;
    if(v.test(a)){alert('Yes')}else{alert('No');}
    }
    </script> 
    <body>
    <form id="form1" name="form1" method="post" action="">
      <label>
      <input type="text" name="num" id="num" />
      </label>
      <label>
      <input type="button" name="Submit" onclick="check()" value="提交" />
      </label>
    </form>
    </body>
    </html>
    测试代码!~不能吧