Skip to content

Instantly share code, notes, and snippets.

@lucien144
Created May 21, 2014 20:38
Show Gist options
  • Save lucien144/7439c2f939e620f9b1bc to your computer and use it in GitHub Desktop.
Save lucien144/7439c2f939e620f9b1bc to your computer and use it in GitHub Desktop.
<?php
function isEmail($value)
{
$atom = "[-a-z0-9!#$%&'*+/=?^_`{|}~]"; // RFC 5322 unquoted characters in local-part
$localPart = "(?:\"(?:[ !\\x23-\\x5B\\x5D-\\x7E]*|\\\\[ -~])+\"|$atom+(?:\\.$atom+)*)"; // quoted or unquoted
$alpha = "a-z\x80-\xFF"; // superset of IDN
$domain = "[0-9$alpha](?:[-0-9$alpha]{0,61}[0-9$alpha])?"; // RFC 1034 one domain component
$topDomain = "[$alpha](?:[-0-9$alpha]{0,17}[$alpha])?";
return (bool) preg_match("(^$localPart@(?:$domain\\.)+$topDomain\\z)i", $value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment