Question

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

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top