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;
}
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;
}