views:

3594

answers:

6

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

A: 

Spring has wonderful validation classes. But I don't see what these or the Commons Validation have to do with e-mail. They're for general validation and binding of values, like HTTP request parameters, to objects. How do you connect them to e-mail? What are you validating? E-mail addresses can be validated with regular expressions. What else is there?

duffymo
Matthew Flaschen
"library" to validate an e-mail address? Sorry, it sounded like far more than that was required. I must have misinterpreted the question.
duffymo
I would hardly characterize redoing a regular expression as reinventing a wheel. There's another argument that says you'd be better off without the dependency on another 3rd party library. Our host Jeff Atwood agrees: http://www.codinghorror.com/blog/archives/001145.html
duffymo
+2  A: 

Apache Commons is generally known as a solid project. Keep in mind, though, you'll still have to send a verification email to the address if you want to ensure it's a real email, and that the owner wants it used on your site.

Matthew Flaschen
I agree with the extra bits you cited, but are those part of the Commons Validation project?
duffymo
+1  A: 

What do you want to validate? The email address?

The email address can only be checked for its format conformance. See the standard: RFC2822. Best way to do that is a regular expression. You will never know if really exists without sending an email.

I checked the commons validator. It contains an org.apache.commons.validator.EmailValidator class. Seems to be a good starting point.

ReneS
A: 

If you're looking to verify whether an email address is valid, then VRFY will get you some of the way. I've found it's useful for validating intranet addresses (that is, email addresses for internal sites). However it's less useful for internet mail servers (see the caveats at the top of this page)

Brian Agnew
+2  A: 

Les Hazlewood has written a very thorough RFC 2822 compliant email validator class using Java regular expressions. You can find it at http://www.leshazlewood.com/?p=23. However, its thoroughness (or the Java RE implementation) leads to inefficiency - read the comments about parsing times for long addresses.

Philip