javascrpt 实现电子邮箱验证

<script language=javascript> 
function mail_test() 
{ 
email=f1.mail.value; 
if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email)) 
{ 
alert("mail格式不对,请重新输入"); 
f1.mail.focus(); 
return false; 
} 
} 
</script> 
<form name="f1" onsubmit="return mail_test();"> 
<input name="mail"> 
<input value="确定" type="submit"> 
</form> 

或者 
<script language=javascript> 
function checkEmail(cEmail) [color=blue]//验证邮箱地址是否正确,cEmail为邮箱地址。[/color] 
{if(cEmail.match(/[\w-]+@{1}[\w-]+\.{1}\w{2,4}(\.{0,1}\w{2}){0,1}/ig)!=cEmail) 
return false 
else 
return true} 
</script> 

<input id=zz><input type=button value=check onclick="if(checkEmail(zz.value))alert('正确');else alert('错误')"> 








你可能感兴趣的:(JavaScript)