0

While running this regex:

if(!preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",  $email)){`

I get the following error message:

Warning: preg_match(): No ending delimiter '^' found in C:\xampp\htdocs\Test\source\index.php on line 28.

Why?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Joe Smith
  • 11
  • 1
  • 1
  • Alternatively, you can use: `if ( ! filter_var($email, FILTER_VALIDATE_EMAIL))` http://php.net/manual/en/filter.examples.validation.php – Wesley Murch Aug 07 '13 at 04:50

1 Answers1

0

preg_match() thinks you're using the carat "^" as the delimiter. Generally, you'll find most people use "/".

if(!preg_match("/^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$/", $email)) {
Shylo Hana
  • 1,792
  • 13
  • 10