转载:http://hi.baidu.com/liyahui/item/1effd710a99cba071894ec84
java类:
public static boolean isVaildEmail(String email){
String emailPattern="[a-zA-Z0-9][a-zA-Z0-9._-]{2,16}[a-zA-Z0-9]@[a-zA-Z0-9]+.[a-zA-Z0-9]+";
boolean result=Pattern.matches(emailPattern, email);
return result;
}
?
js:
<script language="javascript">
function checkMail(){
var strReg="";
var r;
var strText=document.getElementById("email").value;
strReg=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/i;
r=strText.search(strReg);
if(r==-1) {
alert("请填写正确的邮箱!");
document.all(str).focus();
document.all(str).value="";
}
}
</script>
</head>
<body>请填写要验证的邮箱:
<input name="email" type="text" id="email" />
<input name="" type="button" value="验 证" onclick="checkMail();" />
</body>