0

Possible Duplicate:
What is the best Java email address validation method?

I need to know if there is any method in java to implement email validation for addresses like

xyz@yahoo.com,xyz@yahoo.co.in

Community
  • 1
  • 1
the_dopamine
  • 899
  • 6
  • 12
  • 21

2 Answers2

4

You could use org.apache.commons.validator.EmailValidator which is part of Apache Commons Validator.

Or use a Jsr-303 validation framework (e.g. Hibernate Validator) which offers a @Email validator.

jeha
  • 10,562
  • 5
  • 50
  • 69
  • EmailValidator also gives you the option of excluding local email addresses so that the top level domain must be present, which was a requirement for me. – leojh Jan 30 '14 at 19:28
3

Use this code.

static Pattern emailPattern = Pattern.compile("[a-zA-Z0-9[!#$%&'()*+,/\\-_\\.\"]]+@[a-zA-Z0-9[!#$%&'()*+,/\\-_\"]]+\\.[a-zA-Z0-9[!#$%&'()*+,/\\-_\"\\.]]+");
public static boolean isValidEmail(String email) 
{       
    Matcher m = emailPattern.matcher(email);
        return !m.matches();
}
Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Sohan Poonia
  • 146
  • 11