<script>
function checkfloat(s){
  var arr=s.match(/^\d+\.\d+$/);
  return arr!=null
}
alert(checkfloat("1.11"));
alert(checkfloat("a.11"));
alert(checkfloat("1"));
</script>

解决方案 »

  1.   

    判断输入字符是浮点数或整数可以直接用isNaN
    <script>
    function checkfloat(s){
      return !isNaN(s)
    }
    alert(checkfloat("1.11"));
    alert(checkfloat("a.11"));
    alert(checkfloat("1"));
    </script>
      

  2.   

    判断输入字符是浮点数或整数也可用<script>
    function checkfloat(s){
      return /^\d+(\.\d+)?$/.test(s);
    }
    alert(checkfloat("1.11"));
    alert(checkfloat("a.11"));
    alert(checkfloat("1"));
    </script>
    还有<script>
    function checkfloat(s){
      return parseFloat(s).toString()==s;
    }
    alert(checkfloat("1.11"));
    alert(checkfloat("a.11"));
    alert(checkfloat("1"));
    </script>