kgaughan (owner)

Revisions

gist: 30797 Download_button fork
public
Public Clone URL: git://gist.github.com/30797.git
Embed All Files: show embed
Checking if an email address is well formed #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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);
}