Skip to content

Instantly share code, notes, and snippets.

@takamin
Created February 4, 2015 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takamin/9e972b791f28731f04f7 to your computer and use it in GitHub Desktop.
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
<?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