Demonstrating why email regexs are poor.


Matrix of Emails against Email validation checkers:

Key: * indicates deviation from the "validity" of the email
Key: Y* indicates test is lax and would let an invalid email through
Key: N* indicates test is too strict and could potentially block a valid email address (more serious than a Y*)

InputValid?pgregg's validate_email
function
arpad
71 chars
Rejected
42 chars
jome
13 chars
Skiz
42 chars
Lazesharp
160 chars
Shadda
28 chars
Shai-Tan
33 chars
DaSourcerer
223 chars
Slynderdale
72 chars
cronus_
46 chars
asonge
256 chars
zfw_isEmail
function
php-filter_var
function
arpad2
140 chars
NiteLiteW
120 chars
asonge2
221 chars
HM2K
4020 chars
HM2K 2
96 chars
arpad3
225 chars
Jan Goyvaerts http://chris.602.org/temp/email_regex_preg.txt
6353 chars
'name.lastname@domain.com'YYYYYYYN *YYYYYYYYYYYYYY
'.@'NNNNNNNNNNNNNNNNNNNNNN
'a@b'NNNNNNNNNNNNNNNNNNY *NNY *
'@bar.com'NNNNNNNNNNNNNNNNNNNNNN
'@@bar.com'NNNNY *NNNY *NNNNNNNNNNNNN
'a@bar.com'YYYYYYYYYN *YYYYYYYYYYYY
'aaa.com'NNNNNNNNNNNNNNNNNNNNNN
'aaa@.com'NNNNNNY *NNNNNNNNNNNNNNN
'aaa@.123'NNNNNNNNNNY *NNNNNNNNNNN
'aaa@[123.123.123.123]'YYYN *YN *N *N *N *N *N *N *N *N *YYN *YYN *YY
'aaa@[123.123.123.123]a'NNNNY *NNNNNNNNNNNNNNNNN
'aaa@[123.123.123.333]'NNY *NY *NNNNNNNNNNNNNY *NNY *
'a@bar.com.'NNNY *Y *NNNNNNY *NNNNNNNNNN
'a@bar'NNNNNNNNNNNNNNNNNNY *NNY *
'a-b@bar.com'YYYYYYYN *YYYYYYYYYYYYYY
'.@b.com'YYYYYYYN *N *N *YN *YN *N *YN *YN *YYN *
'+@b.c'NNNNY *NNNNNNNNNY *NNNY *NNY *
'+@b.com'YYYN *YYN *N *N *N *YN *YYYYYYYYYY
'a@-b.com'NNY *Y *Y *Y *Y *NY *NY *NY *NNNY *NY *NNY *
'a@b-.com'NNY *Y *Y *Y *Y *NY *NY *NY *NNNY *NY *Y *NY *
'-@..com'NNNY *Y *NY *NNNY *NNNNNNNNNNN
'-@a..com'NNNY *Y *NY *NY *NY *NNNNNNNNNNN
'a@b.co-foo.uk'YYYYYYN *N *YN *YYYYYYYYYYYY
' a@bar.com 'YYN *YYN *N *N *N *N *N *YN *N *N *YN *N *YN *YY
'"hello my name is"@stutter.com'YYYN *YN *N *N *N *N *N *N *N *N *YYN *YYN *YY
'"Test \"Fail\" Ing"@example.com'YYYN *YN *N *N *N *N *N *N *N *N *N *N *N *YYN *YY
'valid@special.museum'YYYYYYYYYYYYYYYYYYYYYY
'invalid@special.museum-'NNNY *Y *NNNNNNY *NNY *NNNY *Y *NY *
'shaitan@my-domain.thisisminekthx'NNNY *Y *Y *NNNNNY *NY *Y *NY *NY *Y *NY *
'test@...........com'NNNY *Y *NY *NY *NY *NNNNNNNNNNN
'foobar@192.168.0.1'NNNNY *NNNNNY *Y *Y *NY *NNNY *NNY *
'"Abc\@def"@example.com'YYYN *YN *N *N *YN *N *N *N *N *YN *N *N *YN *YY
'"Fred Bloggs"@example.com'YYYN *YN *N *N *N *N *N *N *N *N *YYN *YYN *YY
'"Joe\Blow"@example.com'YYYN *YYN *N *YN *N *N *N *N *YN *N *N *YN *YY
'"Abc@def"@example.com'YYYN *YN *N *N *YN *N *N *N *N *YN *N *YYN *YY
'customer/department=shipping@example.com'YYYYYYN *N *YYYYYYN *N *YYYYYY
'$A12345@example.com'YYYYYYN *N *YYYYYYYN *N *YYYYY
'!def!xyz%abc@example.com'YYYYYYN *N *YYYYYYYN *YYYYYY
'_somename@example.com'YYYYYYYYYYYYYYYYYYYYYY
'Test \ Folding \ Whitespace@example.com'YYYYN *N *N *N *N *N *N *YN *N *N *N *N *N *N *N *YN *
'HM2Kinsists@(that comments are allowed)this.is.ok'YYN *N *YN *N *N *N *N *N *N *N *N *N *N *N *N *N *N *YN *
'user%uucp!path@somehost.edu'YYYYYYN *N *YN *YYYYYN *YYYYYY
Total differences 
0

5

17

14

12

22

19

14

15

17

14

13

12

10

10

15

5

12

13

0

12

<?php
/*
 * Source: http://www.pgregg.com/projects/php/code/showvalidemail.php
 *
 * Email Validation (syntax/format only) is frequently a hotly discussed
 * topic on forums, irc channels and blogs.  Some people believe that to be
 * "correct" your pattern should be RFC 822/2822 complient, others fall into
 * the take anything camp.
 * Personally, I believe a more liberal approach is necessary - the spirit of
 * RFCs is "Be strict in what you send and liberal in what you receive".
 * Many email addresses might not be strictly to RFC pattern spec, but they
 * work just fine, and in these days of multibyte characters and "foreign"
 * character sets, the picture becomes a lot more complicated.
 * 
 * This script was put together to test several different email syntax regex
 * validation patterns that I've come across on my travels - though mostly
 * from the EfNet #php irc channel.
 *
 * Author and Copyright of this code: Paul Gregg, 2002-2008
 * http://www.pgregg.com
 * Copyright of the various patterns remain with the named authors.
 *
 */

include "validate_email.inc.phps";


echo <<<EOPAGETOP
<html><head>
 <title>Email regex?</title>
    <style type="text/css">
        * { 
            margin: 10px;
            padding: 2px;
        }
        body {
            background: #f7f7f7;
            //font-size: 12px;
            font-family: tahoma;
        }
        table.file_list {
            border: solid 1px #ccc;
            width: 95%;
            font-size: 12px;
            margin: auto;
        }
        table.file_list td {
            padding: 3px;
        }
        table.file_list .a td {
            background: #eee;
        }
        table.file_list .b td {
            background: #f7f7f7;
        }
        table.file_list .header td {
            background: #ddd;
            font-weight: bold;
        }
        table.file_list .N {
            font-weight: bold;
                }
        table.file_list .Y {
            //font-weight: bold;
                }
    </style>
</head>
<body>
<p>Demonstrating why email regexs are poor.</p>
EOPAGETOP;



$emailregex = array (
    
'pgregg\'s <a href="validate_email.inc.phps">validate_email</a>'     =>  'Function:ValidateEmail',
    
'arpad'           =>  '/[^@]@(?:(?:[a-z\d-]+\.)+[a-z\d]{2,6}|\[(?:\d{1,3}\.){3}\d{1,3}\])\z/si',
    
'Rejected'        =>  '/[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}/i',
    
'jome'            =>  '#^.+@.+\..+$#',
    
'Skiz'            =>  '/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/',
    
'Lazesharp'       =>  "#^[\w.%-]+ @ [\w.%-]+ (com|net|org|gov|edu|mil|int|arpa|aero|biz|coop|info|museum|name|pro|asia|cat|jobs|mail|mobi|post|tel|travel|xxx|co|me) (\.[A-Z]{2})? $#ix",
    
'Shadda'          =>  "/^\w+@\w+(\.\w{2,3})*\.\w+$/",
    
'Shai-Tan'        => "/^\S+@[\w\d.-]{2,}\.[\w]{2,6}$/iU",
    
'DaSourcerer'     => '/^("?)(?i:[a-z0-9!#\$%&\'\*\+\-\/=\?\^_`\{\|\}~]+[a-z0-9!#\$%&\'\*\+\-\/=\?\^_`\{\|\}~\.]*[a-z0-9!#\$%&\'\*\+\-\/=\?\^_`\{\|\}~]+)\\1@(?i:[a-z][a-z0-9\-]+\.)+([a-z]{2}|com|org|net|biz|info|name|aero|biz|info|jobs|museum|name)$/',
    
'Slynderdale'     => '#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s\'"<>]+\.+[a-z]{2,6}))$#si',
    
'cronus_'         => "#\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*#",
    
'asonge'          => "/^[\w!#$%&\'*+-\/=?^_`{|}~]+(?:\.[\w!#$%&\'*+-\/=?^_`{|}~]+)*@(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(?:[a-z0-9-]+\.)+(?:arpa|com|edu|gov|int|mil|net|org|biz|info|name|pro|aero|coop|museum|[a-z]{2}))$/i",
    
'zfw_isEmail'     => 'Function:zfw_isEmail',
    
'php-filter_var'  => 'Function:php_filter_var',
    
'arpad2'          => '/^\s*[\w+." -]+@(?:(?:[a-z\d]+(?:-[a-z\d]+)*\.)+[a-z\d]{2,6}|\[(?:(25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(25[0-5]|2[0-4]\d|[01]?\d?\d)\])\s*$/si',
    
'NiteLiteW'       => "#^[a-z0-9,!\#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!\#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$#",
    
'asonge2'         => '/^(?:[a-z0-9!#$%*\/?|^{}`~&\'+=_.-]+|"(?:(?:\\\\\\\\)*\\\\"|[^\\\\"]+)*")@(?:(\[)(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?(1)\]|)|(?:(?:[a-z0-9]+(?:-[a-z0-9]+)*)+\.)+[a-z]{2,6})$/i',
    
'HM2K'            => '/^((?:(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?(?:(?:[\x41-\x5a\x61-\x7a]|[\x30-\x39]|[\x21\x23-\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b-\x7e])+(?:\x2e(?:[\x41-\x5a\x61-\x7a]|[\x30-\x39]|[\x21\x23-\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b-\x7e])+)*)(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?)|(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?\x22(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?(?:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|[\x21\x23-\x5b\x5d-\x7e])|(?:\x5c[\x01-\x09\x0b\x0c\x0e-\x7f]|(?:\x5c[\x00-\x7f]))))*(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?\x22(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?)|(?:(?:(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?(?:[\x41-\x5a\x61-\x7a]|[\x30-\x39]|[\x21\x23-\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b-\x7e])+(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?)|(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?\x22(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?(?:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|[\x21\x23-\x5b\x5d-\x7e])|(?:\x5c[\x01-\x09\x0b\x0c\x0e-\x7f]|(?:\x5c[\x00-\x7f]))))*(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?\x22(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?))(?:\x2e(?:(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?(?:[\x41-\x5a\x61-\x7a]|[\x30-\x39]|[\x21\x23-\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b-\x7e])+(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?)|(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?\x22(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?(?:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|[\x21\x23-\x5b\x5d-\x7e])|(?:\x5c[\x01-\x09\x0b\x0c\x0e-\x7f]|(?:\x5c[\x00-\x7f]))))*(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?\x22(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?)))*))\x40(?:(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?(?:(?:[\x41-\x5a\x61-\x7a]|[\x30-\x39]|[\x21\x23-\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b-\x7e])+(?:\x2e(?:[\x41-\x5a\x61-\x7a]|[\x30-\x39]|[\x21\x23-\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b-\x7e])+)*)(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?)|(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?\x5b(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?(?:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|[\x21-\x5a\x5e-\x7e])|(?:\x5c[\x01-\x09\x0b\x0c\x0e-\x7f]|(?:\x5c[\x00-\x7f]))))*(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?\x5d(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?)|(?:(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?(?:[\x41-\x5a\x61-\x7a]|[\x30-\x39]|[\x21\x23-\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b-\x7e])+(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?)(?:\x2e(?:(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?(?:[\x41-\x5a\x61-\x7a]|[\x30-\x39]|[\x21\x23-\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b-\x7e])+(?:(?:(?:[\x20\x09]*(?:\x0d\x0a))?[\x20\x09]+)|(?:[\x20\x09]+(?:(?:\x0d\x0a)[\x20\x09]+)*))?))*)))$/',
    
'HM2K 2'          => '/^[\w!#$%&\'*+\/=?^`{|}~.-]+@(?:[a-z\d][a-z\d-]*(?:\.[a-z\d][a-z\d-]*)?)+\.(?:[a-z][a-z\d-]+)$/iD',
    
'arpad3'          =>  '/^(?:"(?:\\\\.|[^"])*"|[^@]+)@(?=[^()]*(?:\([^)]*\)[^()]*)*\z)(?![^ ]* (?=[^)]+(?:\(|\z)))(?:(?:[a-z\d() ]+(?:[a-z\d() -]*[()a-z\d])?\.)+[a-z\d]{2,6}|\[(?:(?:1?\d\d?|2[0-4]\d|25[0-4])\.){3}(?:1?\d\d?|2[0-4]\d|25[0-4])\]) *\z/si',

    
#'php-filter_validate_email' => "/^((\\\"[^\\\"\\f\\n\\r\\t\\v\\b]+\\\")|([\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]+(\\.[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]+)*))@((\\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\\-])+\\.)+[A-Za-z\\-]+))$/",
    #'rfc822'     =>  '#'.perl_rfc822().'#',
    
'Jan Goyvaerts http://chris.602.org/temp/email_regex_preg.txt'        =>  '/\\A(?:(?:(?:\\r\\n)?[ \\t])*(?:(?:(?:[^()<>@,;:\\\\".\\[\\] \\x00-\\x1F]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\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\t])+|\\Z|(?=[\\["()<>@,;:\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*)*:(?:(?:\\r\\n)?[ \\t])*)?(?:[^()<>@,;:\\\\".\\[\\] \\x00-\\x1F]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\["()<>@,;:\\\\".\\[\\]]))|"(?:[^\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*"(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\".\\[\\] \\x00-\\x1F]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\["()<>@,;:\\\\".\\[\\]]))|"(?:[^\\"\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*"(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\".\\[\\] \\x00-\\x1F]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\["()<>@,;:\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\".\\[\\] \\x00-\\x1F]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\["()<>@,;:\\\\".\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*\\>(?:(?:\\r\\n)?[ \\t])*))*)?;\\s*))\\z/',

);
/*
$rfc822 = '#' . perl_rfc822() . '#i';
print $rfc822;
Function ValidateEmail4($emailstr) {
    global $rfc822;
    return (bool)preg_match($rfc822, $emailstr);
}
*/

#http://framework.zend.com/issues/browse/ZF-42
Function zfw_isEmail($value)
    {
        
/**
         * @todo RFC 2822 (http://www.ietf.org/rfc/rfc2822.txt)
         */
        
$atom '[-a-z0-9!#$%&\'*+/=?^_`{|}~]';
        
$domain '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)';
        
$regex '^' $atom '+' '(\.' $atom '+)*\@(' $domain '{1,63}\.)+' $domain '{2,63}$';

        if (
eregi($regex$value))
        {
            return 
$value;
        }

        return 
false;
    }

Function 
php_filter_var($value) {
  if(
filter_var($valueFILTER_VALIDATE_EMAIL) === FALSE) return false;
  return 
$value;
}

$tests = array(
    
'name.lastname@domain.com'                   => true,
    
'.@'                                         => false,
    
'a@b'                                        => false,
    
'@bar.com'                                   => false,
    
'@@bar.com'                                  => false,
    
'a@bar.com'                                  => true,
    
'aaa.com'                                    => false,
    
'aaa@.com'                                   => false,
    
'aaa@.123'                                   => false,
    
'aaa@[123.123.123.123]'                      => true,
    
'aaa@[123.123.123.123]a'                     => false# extra data outside ip
    
'aaa@[123.123.123.333]'                      => false# not a valid IP
    
'a@bar.com.'                                 => false,
    
'a@bar'                                      => false,
    
'a-b@bar.com'                                => true,
    
'.@b.com'                                    => true,  # it does work, honest...
    
'+@b.c'                                      => false# min 2 char tld
    
'+@b.com'                                    => true,
    
'a@-b.com'                                   => false,
    
'a@b-.com'                                   => false,
    
'-@..com'                                    => false,
    
'-@a..com'                                   => false,
    
'a@b.co-foo.uk'                              => true,
    
' a@bar.com '                                => true,
    
'"hello my name is"@stutter.com'             => true,
    
'"Test \"Fail\" Ing"@example.com'            => true,
    
'valid@special.museum'                       => true,
    
'invalid@special.museum-'                    => false,
    
'shaitan@my-domain.thisisminekthx'           => false# tld way too long
    
'test@...........com'                        => false# ......
    
'foobar@192.168.0.1'                         => false# ip need to be []
    // from reading http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx
    
'"Abc\@def"@example.com'                     => true,
    
'"Fred Bloggs"@example.com'                  => true,
    
'"Joe\\Blow"@example.com'                    => true,
    
'"Abc@def"@example.com'                      => true,
    
'customer/department=shipping@example.com'   => true,
    
'$A12345@example.com'                        => true,
    
'!def!xyz%abc@example.com'                   => true,
    
'_somename@example.com'                      => true,
    
'Test \\'.chr(10).' Folding \\'.chr(10).' Whitespace@example.com' => true,
    
'HM2Kinsists@(that comments are allowed)this.is.ok' => true,
    
'user%uucp!path@somehost.edu'                => true,
);


echo 
"<br />\nMatrix of Emails against Email validation checkers:<br />";
echo 
'<br />Key: * indicates deviation from the "validity" of the email';
echo 
'<br />Key: Y* indicates test is lax and would let an invalid email through';
echo 
'<br />Key: <span style="font-weight: bold;">N*</span> indicates test is too strict and could potentially block a valid email address (more serious than a Y*)<br /><br />';

// Display the table header row
echo '<table cellpadding=4 cellspacing=0 class="file_list"><tr class="header"><td>Input</td><td>Valid?</td>';
foreach (
$emailregex as $submitter => $regex) {
  if (
preg_match('/^Function:/'$regex))
    
$regexsize '<br/><i>function</i>';
  else
    
$regexsize '<br/><i>' strlen($regex) . ' chars</i>';
  echo 
'<td>'$submitter$regexsize'</td>';
}
echo 
'</tr>';

$errorcount = array();
$rowcount=0;
foreach (
$tests as $test => $isvalid) {
    
$rowclass = (++$rowcount%2=='a' 'b');
    
$isvalidyn = ($isvalid 'Y' 'N');

    echo 
'<tr class="',$rowclass,'"><td>\''$test'\'</td><td>'$isvalidyn'</td>';
    foreach (
$emailregex as $submitter => $regex) {
      if (!isset(
$errorcount[$submitter])) $errorcount[$submitter] = 0;
      if (
preg_match('/^Function:/'$regex)) { // call the function
        
list($crap$func) = explode(':'$regex);
        
$result = (call_user_func($func$test) !== false);
      } else
        
$result = (preg_match($regex$test) > 0);
      
$resultyn $result 'Y' 'N';
      
printf('<td class="%s">%s%s%s%s</td>',
        (
$result != $isvalid && $result === false) ? 'N' 'Y',
        
''#($result != $isvalid && $result === false) ? '<b>' : '',
        #$resultyn . '(result='.($result?'true':'false').') (resultyn='.$resultyn.')',
        
$resultyn,
        
$result != $isvalid ' *' '',
        (
$result != $isvalid && $result === false) ? '</b>' ''
      
);
      if (
$result != $isvalid$errorcount[$submitter]++;
    }
    echo 
'</tr>';
}
// display "error" totals
echo '<tr><td>Total differences</td><td>&nbsp;</td>';
foreach (
$emailregex as $submitter => $regex) {
  echo 
'<td><hr>'$errorcount[$submitter], '</td>';
}
echo 
'</tr>';
echo 
"</table><br>";

Function 
perl_rfc822() {
#rfc822 regex from http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
    
$rfc822 = <<<EOWTF
(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:
\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ 
\t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\0
31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\
](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+
(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:
(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z
|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)
?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\
r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[
 \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)
?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t]
)*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[
 \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*
)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)
*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+
|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r
\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:
\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t
]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031
]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](
?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?
:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.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]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\"
.\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\
]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\
[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\
r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]
|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \0
00-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\
.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,
;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?
:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*
(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".
\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[
^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]
]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)(?:,\s*(
?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\
".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(
?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[
\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t
])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t
])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?
:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|
\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:
[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\
]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)
?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["
()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)
?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>
@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[
 \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,
;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t]
)*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\
".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?
(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".
\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:
\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[
"()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])
*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])
+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\
.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z
|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(
?:\r\n)?[ \t])*))*)?;\s*)
EOWTF;
  return 
str_replace("\n"''$rfc822);
}

echo 
'<font face="courier">';
show_source(__FILE__);