java 验证邮箱

java 验证邮箱格式正确性(转载)

Java 正则表达式

 

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;
    }
}

 

 

 

private static boolean getEmail(String line){
        Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
        Matcher m = p.matcher(line);
        return m.find();
    }
 

 

你可能感兴趣的:(java,java,正则表达式)