tags:

views:

26

answers:

3
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
+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
+4  A: 

You forgot the delimiters. Add them.

Also note that you regex ignores some perfectly valid addresses (such as [email protected])

Matti Virkkunen
+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
If that uses the RFC e-mail formatting rules, that's awesome. Not sure though: http://bugs.php.net/bug.php?id=43402
banzaimonkey
IIRC now it does, however I'm not 100% sure.
Crozin
Thank You. Thats Much Better, than RegEx which I haven't taken the time to understand. So thanks again!
TechplexEngineer