note 80865 added to function.preg-match

From: Date: Tue, 05 Feb 2008 00:01:27 +0000
Subject: note 80865 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-135776@lists.php.net to get a copy of this message
> This fixes BK's bugs when checking an email address: > > "/^([a-z0-9._-](\+[a-z0-9])*)+@[a-z0-9.-]+\.[a-z]{2,6}$/i" misplaced that * I guess > > Features: > -Accepts + addressing, and must have characters after the + > -No special characters such as: ! # $ % & ' * / = ? ^ ` { | } who needs 'em! > -No spaces. > > Caveats still remaining: > -You should use trim() on your email address first. Trimming... easy fix, add [:space:] or \s to the front and end of the expression > -Allows multiple ...... dots Needs a restructure of the expression - having a different character class before and after dots > -Allows dots in the .wrong places. > -Allows domain names with dashes - in the wrong places. I would come up with the following (mind that I am just getting started with regexes as well): "/^\s*[a-z][a-z0-9]*(\.[a-z0-9][a-z0-9-]*)*(\+[a-z0-9]*)? @[a-z0-9][a-z0-9-]*(\.[a-z0-9][a-z0-9-]*)*\.[a-z]{2,6}\s*$/i" (added linebreak due to technical reasons problems with php.net) The only problem that still applies, is the dashes in the wrong places (though the only wrong place is right before a dot). Fixing this is tricky, I tried using lookbehind, but that did not work. You do have to keep in mind that there may only be one letter between two dots. ---- Server IP: 83.137.20.135 Probable Submitter: 84.82.179.97 ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- https://master.php.net/note/edit/80865 Del: integrated -- https://master.php.net/note/delete/80865/integrated Del: useless -- https://master.php.net/note/delete/80865/useless Del: bad code -- https://master.php.net/note/delete/80865/bad+code Del: spam -- https://master.php.net/note/delete/80865/spam Del: non-english -- https://master.php.net/note/delete/80865/non-english Del: in docs -- https://master.php.net/note/delete/80865/in+docs Del: other reasons-- https://master.php.net/note/delete/80865 Reject -- https://master.php.net/note/reject/80865 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135776) next »