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
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
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.
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();
}