Candid’s brain

Validate e-mail address

Posted on: May 13th, 2008

This PHP code validates an e-mail address according to all rules of the standards I could find:

(preg_match("((?P[-A-Za-z0-9!#\$%&'*+/=?^_`{|}~]|\\\\[\\x00-\\x7f]|[-A-Za-z0-9!#\$%&'*+/=?^_`{|}~]|\\\\[\\x00-\\x7f][-A-Za-z0-9!#\$%&'*+/=?^_`{|}~.]|\\\\[\\x00-\\x7f])*[-A-Za-z0-9!#\$%&'*+/=?^_`{|}~]|\\\\[\\x00-\\x7f]|\"[\\x00-\\x7f]*[\\x00-\\x5b\\x5d-\\x7f]\")@(?P([-a-z0-9]{1,63}\.)*[-a-z0-9]{1,63}))s", $email, $m) && strlen($m["domain-part"]) <= 255)

http://en.wikipedia.org/wiki/E-mail_address has been updated, I don’t know if my code really follows all rules, as I have found there some I hadn’t known. Please correct my code if you know it better.