note 80865 deleted from function.preg-match by felipe

From: Date: Sun, 23 Mar 2008 22:56:52 +0000
Subject: note 80865 deleted from function.preg-match by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137381@lists.php.net to get a copy of this message
Note Submitter: jasperhorn [AT] gma-remove-il (dot) com ---- > 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.

« previous php.notes (#137381) next »