note 96910 added to function.preg-match

From: Date: Mon, 22 Mar 2010 19:31:05 +0000
Subject: note 96910 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-167298@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 204.64.50.78 (proxied: 204.64.28.5) ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- https://master.php.net/note/edit/96910 Del: integrated -- https://master.php.net/note/delete/96910/integrated Del: useless -- https://master.php.net/note/delete/96910/useless Del: bad code -- https://master.php.net/note/delete/96910/bad+code Del: spam -- https://master.php.net/note/delete/96910/spam Del: non-english -- https://master.php.net/note/delete/96910/non-english Del: in docs -- https://master.php.net/note/delete/96910/in+docs Del: other reasons-- https://master.php.net/note/delete/96910 Reject -- https://master.php.net/note/reject/96910 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167298) next »