Java String match email

Description

Java String match email


public class Main {
    public static void main(String[] argv) throws Exception {
        String str = "abc@example.com";
        System.out.println(isEmail(str));
    }//from  w w  w .j  a  v a2 s .  c  o  m

    public static Boolean isEmail(String str) {
        Boolean isEmail = false;
        String expr = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        if (str.matches(expr)) {
            isEmail = true;
        }
        return isEmail;
    }
}



PreviousNext

Related