Created
February 4, 2015 02:20
-
-
Save takamin/9e972b791f28731f04f7 to your computer and use it in GitHub Desktop.
Inspection of e-mail addresses based on the specification of the RFC2822 Addr-spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* e-mail address specification. | |
* | |
* http://blog.livedoor.jp/dankogai/archives/51189905.html | |
* | |
* RFC-2822 3.4.1 Addr-spec specification | |
* https://www.ietf.org/rfc/rfc2822.txt | |
*/ | |
class RFC2822_AddrSpec { | |
/** | |
* check e-mail address | |
*/ | |
static function is_valid($addr) { | |
$atom = "[a-zA-Z0-9_!#\$\%&'*+\\/=?\^`{}~|\-]+"; | |
$dot_atom = "$atom(?:\.$atom)*"; | |
$quoted = '"(?:\\[^\r\n]|[^\\"])*"'; | |
$local = "(?:$dot_atom|$quoted)"; | |
$domain_lit = "\[(?:\\\S|[\x21-\x5a\x5e-\x7e])*\]"; | |
$domain = "(?:$dot_atom|$domain_lit)"; | |
$addr_spec = $local.'@'.$domain; | |
return preg_match('/^'.$addr_spec.'$/', $addr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment