Skip to content

Instantly share code, notes, and snippets.

@rcebrian
Created November 4, 2018 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcebrian/2d2704af9b6b72cc751f4929a238dd78 to your computer and use it in GitHub Desktop.
Save rcebrian/2d2704af9b6b72cc751f4929a238dd78 to your computer and use it in GitHub Desktop.
checks that a mail meets all the requirements
/*
* validateMail: checks that a mail meets all the requirements
* @param mail: a string with the ail that you want to check
* @return true: meet the requirements
* @return false: doesn't meet the requirements
*/
public static boolean mailValidator(String email) {
boolean valid = false;
Pattern pattern = Pattern.compile("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
if (email != null) {
Matcher mather = pattern.matcher(email);
if (mather.find())
valid = true;
}
return valid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment