Matching email addresses

rob_au on 2003-07-21T05:54:27

Matching email addresses with regular expressions is a complex task - The easiest way to go about doing this is to use the massive regular expression which Jeff Friedl demonstrates the construction of in Mastering Regular Expressions.

I found today that sometimes this level of matching is overkill - The scenario was a PHP form where a users' email address is specified. The regular expression from Mastering Regular Expressions worked nicely, but because the RFC allows for the specification of addresses by local username alone, "invalid" email addresses could still be provided. The work around was to edit the source of the regular expression constructor script so that only the addr_spec portion of the RFC specified address specification was matched.

There was of course, no way I was going to edit the regular expression directly - Have you see that thing? :-)