Re: Re: Valid email address syntax script?

From: Date: Wed, 04 May 2005 08:28:40 +0000
Subject: Re: Re: Valid email address syntax script?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-214396@lists.php.net to get a copy of this message
On 3 May 2005, at 19:18, Matthew Weier O'Phinney wrote:
* Jm <frawst1@gmail.com>:
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('/[^@\s]+@([-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

« previous php.general (#214396) next »