What is the best Java email address validation method?

jon077 picture jon077 · Mar 9, 2009 · Viewed 456.7k times · Source

What are the good email address validation libraries for Java? Are there any alternatives to commons validator?

Answer

Aaron Davidson picture Aaron Davidson · May 9, 2011

Using the official java email package is the easiest:

public static boolean isValidEmailAddress(String email) {
   boolean result = true;
   try {
      InternetAddress emailAddr = new InternetAddress(email);
      emailAddr.validate();
   } catch (AddressException ex) {
      result = false;
   }
   return result;
}