note 54171 deleted from function.preg-match by colder

From: Date: Mon, 18 Jun 2007 18:23:38 +0000
Subject: note 54171 deleted from function.preg-match by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127607@lists.php.net to get a copy of this message
Note Submitter: i at camerongreen dot org ---- 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

« previous php.notes (#127607) next »