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

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

Related Posts with Thumbnails