请问怎么判断输入框的值是以w或v或DT或数字开头,用这些表达式/^w|v|(DT)|\d+/好像是这么写

解决方案 »

  1.   

    学习了O.0,测试通过
    <html>
    <head>
    <script>
    function test_pattern(current_form)
    {
    var reg=/^w|v|(DT)|\d+/;
    if(reg.test(current_form.test.value)){
    alert('match');
    }
    else {
    alert('not match');
    }

    }
    </script>
    </head>
    <body>
    <form>
    <input type="text" name="test">
    <p></p>
    <input type="button" onClick="test_pattern(this.form)">
    </form>
    <body>

    </html>
      

  2.   

    /^(w|v|(DT)|\d+)/
    这个括号最好加上,|的优先级很低的。