On 3 May 2005, at 19:18, Matthew Weier O'Phinney wrote:

* Jm <[EMAIL PROTECTED]>:

Does anyone have a nice email address syntax checking script they'd
like to share? Regular expression-based anyone? TIA.


I use the following regex:

    preg_match('/[EMAIL PROTECTED]@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email)

I believe I got it out of the PHP Cookbook, by David Sklar, but I can't
remember for certain. It's not 100% accurate, but I rarely have
complaints from users whose emails don't validate.

I've used this one quite heavily. It doesn't go as far as checking TLDs, but it's quite tight on RFC2822 and allows things like numeric addresses:


preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\ $\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-] (?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61} [a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]? \d{1,2}|2[0-4]\d|25[0-5])\]))$/', $email);

I got it from here - they have some more and some commercial products that go further:

http://www.hexillion.com/samples/#Regex

Marcus

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



Reply via email to