62,623
社区成员
发帖
与我相关
我的任务
分享
/**
* E-mail正则表达式 如:hlt@qq.com,hlt_hlt@abc.com,hlt_asdf_234@jdlssoft.com.cn
* regEmailStr = "\\w+(@)\\w+(\\.\\w+)(\\.\\w+|)";
*/
String[] email = new String[] { "hello23@abc.com", "hel&lo23",
"hlt@jdlssoft.com.cn", "hlt.hlt@163.com", "hlt_hlt@qq.com",
"11858817@qq.com" };
String regEmailStr = "\\w+(@)\\w+(\\.\\w+)(\\.\\w+|)";
for (int i = 0; i < email.length; i++) {
System.out.println(email[i] + "是email?" + email[i].matches(regEmailStr));
}
/**
* 判断是不是合法Email email Email地址
*/
public static boolean isEmail(String email) {
try {
if (email == null || email.length() < 1 || email.length() > 256) {
return false;
}
String check = "^([0-9a-zA-Z]+[_.0-9a-zA-Z-]+)@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2,3})$";
Pattern regex = Pattern.compile(check);
Matcher matcher = regex.matcher(email);
boolean isMatched = matcher.matches();
if (isMatched) {
return true;
} else {
return false;
}
} catch (RuntimeException e) {
return false;
}
}