note 96910 deleted from function.preg-match by danbrown

From: Date: Wed, 03 Aug 2011 13:08:37 +0000
Subject: note 96910 deleted from function.preg-match by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-182140@lists.php.net to get a copy of this message
Note Submitter: eric at devotia dot com ---- I see quite a few email address validation patterns below that seem to me to be overly strict. using the username@domain.tld model: username: the rules are dictated by the receiving email server, this means that in theory anything goes here. I could write my own email server and dictate my own rules. domain: Domain names are regulated and there are rules. Still I would opt for a loose interpretation and not bother checking length. tld: Vanity TLD's are just around the corner, once again try not to be too restrictive. So using a loose pattern, like so: preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', $email) username: at least 1 character and it isn't an @ domain: at least 1 character and contains only valid characters. tld: at least 1 character, alpha only (actually not entirely sure what the new custom TLD's will allow may need to broaden the scope here). A strict pattern is not going to guarantee the result of a valid email address (it won't make sure it exists), but many of the patterns below can result in a syntactically valid email address not being accepted (not good). Spaces and quotes while rare are still occasionally encountered in the username section of an address. I actually see both with some regularity. Domain name length, while there is the 63 character (255 overall) per section limitation I think we can pretty much agree that someone isn't likely to give you a false email address by violating that 1. There is at least 1 single character domain name that I am aware of, qwest owns q.com so in theory bob@q.com could be an actual email address.

« previous php.notes (#182140) next »