Skip to content

Instantly share code, notes, and snippets.

@kgaughan
Created December 1, 2008 18:31
Show Gist options
  • Save kgaughan/30797 to your computer and use it in GitHub Desktop.
Save kgaughan/30797 to your computer and use it in GitHub Desktop.
function is_valid_local_part($local) {
// I'm not entirely sure about this regex, but it seems to fit was RFC2822 specifies.
return preg_match("@^[-a-z0-9!#\$%&'*+/=?^_`{|}~]+(\.[-a-z0-9!#\$%&'*+/=?^_`{|}~]+)*\$@", $local);
}
function is_well_formed_email_address($email) {
// We ignore legacy addresses and local addresses.
$parts = explode('@', $email, 2);
if (count($parts) != 2) {
return false;
}
list($local, $host) = $parts;
return is_valid_local_part($local) && is_well_formed_hostname($host);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment