下面代码在FF中第一次通过验证,当第二次点击“check email”的时候提示出错,请帮忙看看是什么问题。<html>
<head>
<style type="text/css">
* { font-family:Calibri; }
</style></head>
<body> <input type="text" id="uc-email" name="email" size="40"  value="[email protected]"/>       
 <input type="button" value="Check Email" onclick="CheckEmail();" />
<script type="text/javascript">
    function CheckEmail() {
        var email = document.getElementById("uc-email").value;
        if (email != "") {
            if (!(/^[a-z][\w.-]+@[\w.-]+.[a-z]+$/gi.test(email))) {
                alert("Invalid e-mail address");
            }
        }
    }
</script></body>
</html>

解决方案 »

  1.   

    兄弟,你的代码写的不对,改过来吧<script type="text/javascript">
      function CheckEmail() {
      var email = document.getElementById("uc-email").value;
      if (email != "") {
      if (!(/^[a-z][\w.-]+@[\w.-]+\.[a-z]+$/gi.test(email))) {
      alert("Invalid e-mail address");
      }
      }
      }
    </script>
      

  2.   

    <html>
    <head>
    <style type="text/css">
    * { font-family:Calibri; }
    </style>
    <script type="text/javascript">
      function CheckEmail() {
      var email = document.getElementById("uc-email").value;
      if (email != "") {
      if (!(/^[a-z][\w.-]+@[\w.-]+.[a-z]+$/gi.test(email))) {
      alert("Invalid e-mail address");
      }
      }
      }
    </script>
    </head>
    <body> <input type="text" id="uc-email" name="email" size="40" value="[email protected]"/>   
     <input type="button" value="Check Email" onclick="CheckEmail();" /></body>
    </html>
      

  3.   

    请注意,这个问题要在Firefox中测试,谢谢!
      

  4.   

    不好意思,可能我没把问题讲清楚。问题是我在ie中测试没有任何问题,在Firefox中第一次点击“check email”按钮是通过验证,第二次点击的时候跳出消息“invalid email address”。希望我能讲的明白。多谢!
      

  5.   

    加了g之后
    ff下一直引用的是同一个正则有一些解释
    http://bbs.51js.com/thread-78431-1-1.html
      

  6.   


    多谢,test是单次匹配,而 /g 是多次搜索。