NYCPHP Meetup

NYPHP.org

[nycphp-talk] Validating Email Addresses

Chris Shiflett shiflett at php.net
Thu Dec 2 15:03:26 EST 2004


--- Dan Cech <dcech at phpwerx.net> wrote:
> I've come up against an interesting little problem, and wondered
> if anyone had any input for me.
> 
> I'm trying to validate email addresses like:
> 
> Joe Bloggs <joe at example.com>

That's a valid format for the From header (not sure it can really be
called an email address, but maybe), but aren't quotes required around the
name?

You might think it's less cool than matching everything with a single
pattern, but can't you easily break this up into name and email address?
There are plenty of patterns to help make sure a string looks like an
email address (I use the one in the Cookbook), so you just need to augment
that by breaking up your string into a name and email address.

The email address is probably everything to the right of the last space,
without the angle brackets (if present). The name is everything else,
without the quotes (if present).

Hope that helps.

Chris

=====
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly     HTTP Developer's Handbook - Sams
Coming February 2005        http://httphandbook.org/



More information about the talk mailing list