JavaScript验证:
New Documentfunction 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;
}
请输入email:
java验证
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();
}
分享到:
2009-05-12 23:19
浏览 2736
评论