note 54171 added to function.preg-match
| From: | iatcamerongreendotorg at osu1 dot php dot net | Date: | Sun, 26 Jun 2005 03:01:56 +0000 |
| Subject: | note 54171 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90952@lists.php.net to get a copy of this message | ||
The isvalidemail function has any number of things wrong with it, for a start there is a missing )
bracket so it won't compile.
Once you fix that, the delimiters used give me an error, so you need to enclose it in forward
slashes. Using word boundaries as delimeters is a bad idea as any string that contained a valid
email anywhere in it (along with who knows what else, maybe a CSS attack or SQL injection) would be
returned as a valid email.
Moving on it then only accepts emails in uppercase, the author of this expressions email address for
instance won't pass his own regular expression.
I don't have time at the moment to look up the appropriate rfc, but until someone puts up a
better one here is my email checking function which at least compiles :)
function isValidEmail($email_address) {
$regex = '/^[A-z0-9][\w.-]*@[A-z0-9][\w\-\.]+\.[A-z0-9]{2,6}$/';
return (preg_match($regex, $email_address));
}
Note : It doesn't accept emails with percentage signs (easy to change) and it requires the user
id, first subdomain and last subdomain to start with a letter or number.
Cameron Green
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54171
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54171&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54171&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54171&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54171&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54171&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54171&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54171&report=yes
Search -- http://master.php.net/manage/user-notes.php