Java isEmail

(No Ratings Yet)
 Loading ...

isEmail() method for Java checks if an email address is valid or not. returns boolean.

1
2
3
4
5
6
7
public static String emailPattern = "^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$";
 
public static boolean isEmail(String email) {
  Pattern p = Pattern.compile(emailPattern); // Set the email pattern string
  Matcher m = p.matcher(email); // Match the given string with the pattern
  return m.matches();
}
Bookmark and Share

Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.

Related Posts with Thumbnails

tags: ,

2 Responses to “Java isEmail”

  1. 1
    Albert Says:

    Muchas gracias……!!!!!!

  2. 2
    Albert Says:

    Hay que importar esto:

    java.util.regex.Pattern
    java.util.regex.Matcher

Leave a Reply