Email Validation Function - ANDROID - Helper

Wednesday, April 18, 2012

Email Validation Function

Below code shows how to validate an email
public boolean validateEmail(String email) {
 Pattern pattern;
 Matcher matcher;
 String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
 pattern = Pattern.compile(EMAIL_PATTERN);
 matcher = pattern.matcher(email);
 return matcher.matches();
}


No comments:

Post a Comment