[size=large]JavaScript验证:[/size]
[size=large]java验证[/size]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
function CheckEmail(form){
var res=true;
var email = form.Email.value;
var pattern = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
flag = pattern.test(email);
if(!flag){
res=false;
form.Email.focus();
}
if(email.length!=0){
if (email.charAt(0)=="." || email.charAt(0)=="@"|| email.indexOf('@', 0) == -1 || email.indexOf('.', 0) == -1 || email.lastIndexOf("@")==email.length-1 || email.lastIndexOf(".")==email.length-1){
res = false;
form.Email.focus();
}
}else{
res=false;
form.Email.focus();
}
if(res){
document.getElementById('checkmsg').innerHTML="可以使用的Email!";
}else{
document.getElementById('checkmsg').innerHTML="Email格式错误!";
}
return false;
}
</script>
</HEAD>
<BODY>
<form name="checkForm" >
请输入email:<input type="text" name="Email" value="">
<span id="checkmsg"></span><br />
<input type="button" onclick="CheckEmail(this.form);" value="验证">
</form>
</BODY>
</HTML>
[size=large]java验证[/size]
public boolean checkEmail(String email){
String regex = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(email);
return matcher.find();
}