NYCPHP Meetup

NYPHP.org

[nycphp-talk] Validating Email Addresses

Dan Cech dcech at phpwerx.net
Thu Dec 2 14:09:53 EST 2004


Adam Maccabee Trachtenberg wrote:
> On Thu, 2 Dec 2004, Daniel Krook wrote:
> 
>>>Joe Bloggs <joe at example.com>
>>
>>As I understand it, this format which includes the names, brackets and
>>whitespace is RFC822 compliant
>>[http://www.ietf.org/rfc/rfc0822.txt?number=822] .    If you want it to
>>accept the format above, will need an RFC822 compliant parser like the
>>Perl module, although your regex seems to work ok for the most common
>>format.
>>
>>I would recommend searching for a reasonable sample of RFC822 compliant
>>addresses and run them through, or study examples such as PEAR Mail's
>>RFC822.php [http://cvs.php.net/co.php/pear/Mail/Mail/RFC822.php?r=1.18].

Yep, for my purposes I think I'll be able to get by with:

/^(?:(["]?)([^<>]+?)\1\s*)?(?:<)?(([^!"#$%()*,:;<>@\[\]\\`|]+)@((?:[\w-]+\.)+[a-z0-9]{1,4}))(?:>?)$/i

I also came across the imap_rfc822_parse_adrlist() function, which is 
obviously seldom used because of the unwieldy name ;)

> Comments (and nested comments) are the real bitch here. I suggest you
> pretend they don't exist. :)

That was the plan.

Dan

> -adam
> 




More information about the talk mailing list