js验证电子邮箱格式是否正确的代码

 <script language="javascript" type="text/javascript">
     function CheckEmail(yx)
     {
         var strReg = /^\w+((-\w+)|(\.\w+))*\@{1}\w+\.{1}\w{2,4}(\.{0,1}\w{2}){0,1}/ig;
         return(strReg.test(yx));
     } 
</script>
if(!CheckEmail(document.getElementById("txtMail").value.trim())){          
           alert('电子邮箱格式不正确!');
           document.getElementById("txtMail").focus();
           return false;
       }
posted @ 2011-08-11 22:02  风一样的大叔  阅读(356)  评论(0编辑  收藏  举报