Created
November 4, 2018 23:26
-
-
Save rcebrian/2d2704af9b6b72cc751f4929a238dd78 to your computer and use it in GitHub Desktop.
checks that a mail meets all the requirements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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