各位兄弟姐妹:   小弟想用一正则表达式来验证email地址的有效性,要求email地址的后缀必须是@abc.com.cn,可不知道这正则表达式该怎么写?各位老大帮帮忙呀,兄弟在这谢过了!

解决方案 »

  1.   

    function checkEmail(strEmail) { 
      var myReg = /^[_a-zA-Z0-9_]{1,}[a-z0-9\.\-\_]{0,}@[a-z0-9\_\-]{2,}([\.][a-z]{2,6}){1,3}$/; 
      if(myReg.test(strEmail)) return true; 
      return false; 
     }
      

  2.   

    楼上的兄弟,你写的这个我也知道,我要验证的是mail的后缀名必须是@abc.com.cn的,就是不知道这个正则表达式怎么写
      

  3.   

    偷懒了。抄来用,修改为
    function checkEmail(strEmail) { 
      var myReg = /^[_a-zA-Z0-9_]{1,}[a-z0-9\.\-\_]{0,}@abc.com.cn$/; 
      if(myReg.test(strEmail)) return true; 
      return false; 
     }
      

  4.   

    偷懒了。抄来用,修改为
    function checkEmail(strEmail) 
    {
         return /^\w+[^@]*@abc.com.cn$/.test(strEmail);
    }
      
      

  5.   

    要验证@abc.com.cn的后缀名,可以直接这样写死吗?
      

  6.   

    <script language=javascript>
    function RegexMatch(str)
    {
    return /www\.sohu\.com(.*)/.exec(str)[1];
    }alert(RegexMatch("href=\"www.sohu.com/passive/love.jpg"));
    </script>直接写个txt文档,帖进去,保存成test.htm。试试?
      

  7.   

    帖错了。这个<script language=javascript>
    function checkEmail(strEmail) 
    {
         return /^\w+[^@]*@abc.com.cn$/.test(strEmail);
    }alert(checkEmail("[email protected]"));
    alert(/^\w+[^@]*@abc.com.cn$/.exec("[email protected]"));
    </script>
      

  8.   

    function CheckEmailValidity(oSrc, args)
        {
        
            String.prototype.Trim  = function(){return this.replace(/^\s+|\s+$/g,"");}
          
          
            var pattern = /^\[a-zA-Z0-9._%-][email protected]$/
            var emailsTxt = args.Value;
            
            if(emailsTxt.Trim() == '')
                 return;
            var emails = emailsTxt.split(";");
            var i;
            for (i in emails)
            {if (emails[i].Trim()=="") continue;
               var matches = pattern.exec(emails[i].Trim());
               if (matches == null || emails[i].Trim() != matches[0])
               {
                    args.IsValid = false;
                    return;
               }
             }
        }我的代码是这样的