Re: [OxLUG] Email address validation

Top Page
Delete this message
Reply to this message
Author: Paul Warren
Date:  
To: Oxfordshire Linux User Group Discussion List
Subject: Re: [OxLUG] Email address validation

On 17 Jun 2008, at 10:51, Tom Walker wrote:
> -------- Original-Nachricht --------
>>
>> There's only one way to do email validation properly:
>>
>> 1. Read the RFC
>> 2. Implement it.
>>
>
> There is another way...
>
> 1. Be aware of the RFC
> 2. Find someone else who has already done it ;-)
> 3. Judge it's quality.
>
> http://commons.apache.org/validator/apidocs/org/apache/commons/
> validator/routines/package-summary.html#other.email
>
> ( http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/
> main/java/org/apache/commons/validator/EmailValidator.java?
> revision=658832&view=markup )
>
>
> I would guess that the apache commons implementation is fairly
> widely used, so has hopefully had lots of testing and bug fixes.
> Always better than maintaining your own IMO.


Experience has shown that me that that hope is often optimistic, and
wide use is by no means a guarantee of quality.

The link you provide demonstrates a third way:

1. Find someone else who has already implemented the RFC accurately
2. Modify the code until it works in your preferred language:

/**
* Recursively remove comments, and replace with a single
space. The simpler
* regexps in the Email Addressing FAQ are imperfect - they
will miss escaped
* chars in atoms, for example.
* Derived From Mail::RFC822::Address
* @param emailStr The email address
* @return address with comments removed.
*/
protected String stripComments(String emailStr) {

(To be fair, only that function has been lifted directly from the
Perl module, the rest of it looks like a fairly accurate
implementation based on the RFC822 grammar)

Paul