Skip to content

Instantly share code, notes, and snippets.

@gorrotowi
Last active November 24, 2015 22:40
Show Gist options
  • Save gorrotowi/b41595c368305cf174dc to your computer and use it in GitHub Desktop.
Save gorrotowi/b41595c368305cf174dc to your computer and use it in GitHub Desktop.
Validation mail in java
private final static Pattern EMAIL_ADDRESS_PATTERN = Pattern
.compile(/*"^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@"
+ "((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
+ "[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\."
+ "([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
+ "[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+ "([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$"*/
"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}");
public static boolean isMail(String email) {
return EMAIL_ADDRESS_PATTERN.matcher(email).matches();
}
//Example to use
if(isMail(edtxMail.getText().toString())){
//do something
} else {
//do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment