java code for regex of email validation
This question already has an answer here:
Real world email validation is not so primitive task and it was already solved many times. I'd suggest you not to re-invent the wheel but use Apache Commons EmailValidator.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EmailValidator {
private Pattern pattern;
private Matcher matcher;
private static final String EMAIL_PATTERN =
"^[_A-Za-z0-9-+]+(.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(.[A-Za-z0-9]+)*(.[A-Za-z]{2,})$";
public EmailValidator() {
pattern = Pattern.compile(EMAIL_PATTERN);
}
/**
* Validate hex with regular expression
*
* @param hex
* hex for validation
* @return true valid hex, false invalid hex
*/
public boolean validate(final String hex) {
matcher = pattern.matcher(hex);
return matcher.matches();
}
}
链接地址: http://www.djcxy.com/p/16570.html
上一篇: 什么是电子邮件地址的正确表达式?
下一篇: 正则表达式的电子邮件验证的Java代码