Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php preg_match with email validation issue

Tags:

php

I am validating email address using php with preg_match function. But I keep getting following error

preg_match(): No ending delimiter '^' found

here is my pattern for preg_match

$pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";

How to fix this?

like image 937
Om3ga Avatar asked Nov 19 '12 04:11

Om3ga


2 Answers

Just use:

$pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i";
like image 153
Shoe Avatar answered Sep 28 '22 00:09

Shoe


Maybe using

filter_var($email, FILTER_VALIDATE_EMAIL);

Would be an easier approach.

like image 39
André Keller Avatar answered Sep 27 '22 23:09

André Keller