|
Posted by Marcus Bointon on 05/04/05 11:28
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
[Back to original message]
|