1

Following is the regex I am trying to use

$eregicheck = "^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}\$";

I changed the following lines

return eregi($eregicheck, $emailtocheck);

to

return preg_match($eregicheck, $emailtocheck);

But I dont know why I am getting the error

Warning: preg_match() [function.preg-match]: Unknown modifier '_'
Venkateshwaran Selvaraj
  • 1,745
  • 8
  • 30
  • 60

2 Answers2

1

Try:

^([-!#\$%&'*+./0-9=?A-Z\^_`a-z{|}~])+@([-!#\$%&'*+/0-9=?A-Z\^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}\$

You need to escape ^. It is a special character, which provides instructions to RE.

Kohjah Breese
  • 4,008
  • 6
  • 32
  • 48
1

You're getting this error because php requires delimiters before and after the regex pattern, which in your case it assumes to be ^ and after the delimiters follow the modifiers, in your case _. Since there's no such modifier hence the error. Change the code to:

$eregicheck = "/^([-!#\$%&'*+.\/0-9=?A-Z^_`a-z{|}~])+@([-!#\$%&'*+\/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}\$/";

P.S.: That seems like quite a complex regex, are you sure it can't be simplified? :P

php_nub_qq
  • 15,199
  • 21
  • 74
  • 144