note 69540 added to function.preg-match

From: Date: Sat, 09 Sep 2006 12:01:55 +0000
Subject: note 69540 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-116956@lists.php.net to get a copy of this message
I've seen some regexp's here to validate email addresses. I just wanted to add my own version which accepts the following formats in front of the @-sign: 1. A single character from the following range: a-z0-9!#$%&*+-=?^_`{|}~ 2. Two or more characters from the previous range including a dot but not starting or ending with a dot 3. Any quoted string After the @-sign there is the possibility for any number of subdomains, then the domain name and finally a two letter TLD or one of the TLD's specified. And finally the check is case insensitive. I used the info on this page and in the RFCs to come to this format. If anybody sees any possible improvement I'd be happy to hear from you. <?php function isValidEmailAddress($address='') { $pattern = '/^(([a-z0-9!#$%&*+-=?^_`{|}~]'._ '[a-z0-9!#$%&*+-=?^_`{|}~.]*'._ '[a-z0-9!#$%&*+-=?^_`{|}~])'._ '|[a-z0-9!#$%&*+-?^_`{|}~]|'._ '("[^"]+"))'._ '[@]'._ '([-a-z0-9]+\.)+'._ '([a-z]{2}'._ '|com|net|edu|org'._ '|gov|mil|int|biz'._ '|pro|info|arpa|aero'._ '|coop|name|museum)$/ix'; return preg_match ($pattern, $address); } ?> PS: I have the pattern-code on one line, but I had to split it up for this post...I hope it still works this way but haven't tested it. If the code gives an error try removing all the extra lines... ---- Server IP: 194.109.193.119 Probable Submitter: 212.64.30.209 ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- https://master.php.net/note/edit/69540 Del: integrated -- https://master.php.net/note/delete/69540/integrated Del: useless -- https://master.php.net/note/delete/69540/useless Del: bad code -- https://master.php.net/note/delete/69540/bad+code Del: spam -- https://master.php.net/note/delete/69540/spam Del: non-english -- https://master.php.net/note/delete/69540/non-english Del: in docs -- https://master.php.net/note/delete/69540/in+docs Del: other reasons-- https://master.php.net/note/delete/69540 Reject -- https://master.php.net/note/reject/69540 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116956) next »