regular expression for email validation in Java

aks picture aks · May 4, 2010 · Viewed 18.4k times · Source

I am using the follwoing regular expression

(".+@.+\\.[a-z]+")

Bit it accepts #@#.com as a valid email. What's the pattern I should use?

Answer

CoolBeans picture CoolBeans · May 4, 2010

You should use apache-commons email validator. You can get the jar file from here.

Here is a simple example of how to use it:

import org.apache.commons.validator.routines.EmailValidator;

boolean isValidEmail = EmailValidator.getInstance().isValid(emailAddress);