Re: Regex for email validation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This one time, at band camp, Yeti <yeti@xxxxxxxxxx> wrote:

> <?php
> # this one worked fine for me, but it does not cover the full RFC
> like: "name" name@xxxxxxxxxxxxx OR name <name@xxxxxxxxxxxxx>
> $regex = "^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$";
> if (eregi($regex, $email)) {
>  // do something
> }
> # Beware that the filter functions only work under PHP5+. If your PHP
> supports them they should be the preferred choice
> ?>

There is no silver bullet regex to validate all RFC compliant email address.
Many have tried, but they all fail at some point. The best you can do is
cater to most _sane_ addresses.

And when the domain name space is opened up, well, you will back to strpos() and @

Kevin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux