实现原理,实际上就是输入一个字符串,之后通过正则表达式验证此字符串是否符合邮箱的格式规范,通过以下工具类即可:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegisterCheck {
/**
* 验证输入的邮箱格式是否符合
* @param email
* @return 是否合法
*/
public static boolean emailFormat(String email)
{
boolean tag = true;
final String pattern1 = "^([a-z0-9A-Z]+[-|//.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?//.)+[a-zA-Z]{2,}$";
final Pattern pattern = Pattern.compile(pattern1);
final Matcher mat = pattern.matcher(email);
if (!mat.find()) {
tag = false;
}
return tag;
}
}
正则表达式啊
String reg = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
String email = "sxhsfasdfz@163.com";
boolean isValidaEmail = email.matches(reg);
System.out.println(email.matches(reg));
String reg = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
String email = "sxhsfasdfz@163.com";
boolean isValidaEmail = email.matches(reg);
System.out.println(email.matches(reg));
String checkPattern = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
Pattern regex = Pattern.compile(checkPattern);
Matcher matcher = regex.matcher(email);
面目狰狞