请问各位高手,如何对textbox输入的信息判断只能是数字或小数点,最后用javascript实现?

解决方案 »

  1.   

    呵,更正一下,应该是
    /^\d+(\.\d+)?$/.test(你的值)
      

  2.   

            var str = form1.TextBox1.value;
            var num=str.match(/^[0-9\.]+$/);
            if(num!=null)
                alert("true");
            else
                alert("false");
      

  3.   

            var i=0;
            var str = form1.TextBox1.value;
            var strvalues = "0123456789.";
            for(i=0; i< str.length; i++)
            {
                if(strvalues.indexOf(str.charAt(i)) == -1) return false;
            }
            return true;
      

  4.   


    <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    <html>
    <head>
    <title> new document </title>
    <script language="javascript">
    <!--
    function validText() {
    var str = form1.TextBox1.value;
    var num=str.match(/^[0-9\.]+$/);
    if(num!=null) {
    alert("true");
    } else {
    alert("false");
    form1.TextBox1.value = '';
    }
    }
    //-->
    </script>
    </head><body>
    <form method="post" action="" id="form1">
    <input type="text" name="TextBox1" id="TextBox1" onkeydown="validText();">
    </form>
    </body>
    </html>