2

With the following code

$regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
    ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
    ."\.([a-z]{2,}){1}$";

    if(!preg_match($regex,$subemail)){
      $form->setError($field, "* Email invalid");
    }

    $subemail = stripslashes($subemail);
}

I am receiving the following error

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found 

Any help would be greatly appreciated.

djot
  • 2,952
  • 4
  • 19
  • 28
  • Even if you would fix your delimiters your pattern would fail on **a lot** of emailaddresses: https://emailtester.pieterhordijk.com/test-pattern/NTE – PeeHaa Sep 28 '13 at 22:06
  • http://php.net/manual/en/function.filter-var.php – elclanrs Sep 28 '13 at 22:07

2 Answers2

0

Right now it thinks the ^ is the opening delimiter, and therefore is expecting another one at the end. You can use any number of delimiters, such as / and /, or @ and @, or < and >, etc. The one below uses / and / as its opening/closing delimiters:

     $regex = "/^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
         ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
         ."\.([a-z]{2,}){1}$/";
jerdiggity
  • 3,655
  • 1
  • 29
  • 41
0

You must surround your pattern with # or / like this : "#[abc]+#"

Personnaly I use # because it is more visible than /

For email validation standard PHP function use filter_var('bob@example.com', FILTER_VALIDATE_EMAIL) (see http://www.php.net/manual/en/function.filter-var.php)

56ka
  • 1,463
  • 1
  • 21
  • 37