NYCPHP Meetup

NYPHP.org

[nycphp-talk] Preg_match email address

Jeff jsiegel1 at optonline.net
Mon Sep 15 13:22:52 EDT 2003


Thanks for pointing this out (I think you may have pointed it out in the
earlier thread on this issue).

Jeff Siegel

-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org]
On Behalf Of David Sklar
Sent: Monday, September 15, 2003 10:33 AM
To: NYPHP Talk
Subject: RE: [nycphp-talk] Preg_match email address


On Monday, September 15, 2003 10:56 AM,  wrote:

> I'm hoping those who are more adept at regular expressions could tell
> me if this will validate the majority of email addresses...it seems
> like it will but...
>
> '/^[ a-z0-9-_]+(.[
> a-z0-9-_]+)*@[a-z0-9-]+(.[a-z0-9-_]+)*(.[a-z]{2,3})$/i',

This regex is too broad. You need to escape the periods in the regex so
they
match just ".", not any character. You allow usernames that begin with "
" -- do you really want that? The regex also allows domain names that
begin
with "-", e.g. foo at -bar.com, which are not valid. Some mail servers
allow
individual users to create aliases by appending their username with a
"+",
i.e. "foo+list at bar.com", "foo+shop at bar.com" -- your regex does not allow
+
signs in usernames.

I know this has come up on the list before, but I'll put in a
recommendation
for using the techniques discussed in Recipe 13.5 in PHP Cookbook. There
are
two regexes there and some other techniques for verifying addresses,
along
with the plusses and minuses of each. If you don't own a copy of PHP
Cookbook (why not?!:) you can download the example code from
http://examples.oreilly.com/phpckbk/phpcbbk_examples.zip

David

_______________________________________________
talk mailing list
talk at lists.nyphp.org
http://lists.nyphp.org/mailman/listinfo/talk




More information about the talk mailing list