if(strlen($_REQUEST['email']) >= 0 && preg_match('^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$', $_REQUEST['email']))
{
$error = true;
echo "Please enter a valid Email address";
}
Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in /var/www/team2648/OPIS/register.php on line 30
views:
26answers:
3
+3
A:
preg_match requires opening and closing delimiters like perl. You want to include, say, a slash at the beginning and ending of the regex string like
'/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'
Andrew
2010-08-27 22:47:42
+4
A:
You forgot the delimiters. Add them.
Also note that you regex ignores some perfectly valid addresses (such as [email protected]
)
Matti Virkkunen
2010-08-27 22:47:50
+1
A:
PHP comes with built-in function for validating some popular data like URLs, emails etc. - it's called filter_var()
.
if ($_REQUEST['email'] && filter_var($_REQUEST['email'], FILTER_VALIDATE_EMAIL)) {
// This makes your code much cleaner!
}
Crozin
2010-08-27 22:57:52
If that uses the RFC e-mail formatting rules, that's awesome. Not sure though: http://bugs.php.net/bug.php?id=43402
banzaimonkey
2010-08-27 23:09:32
IIRC now it does, however I'm not 100% sure.
Crozin
2010-08-27 23:16:32
Thank You. Thats Much Better, than RegEx which I haven't taken the time to understand. So thanks again!
TechplexEngineer
2010-08-27 23:17:26