0

the code is not running can anyone explain why ?

$string1 = "Dean_Johns123@cyber.net.uk";    //Example Email

$pattern = "/^[a-z][_][A-Z][_][0-9]*(@).[a-zA-Z]{2,9}[a-zA-Z]{2,3}.[a-zA-Z]{2}$/";

if(preg_match($pattern , $string1))
{
    echo " valid email";
}
else
{
    echo "not valid";
}
Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49
  • The code is running and works, but you use bad syntax. About your regex you already answered. But if you are interested, you can look [http://emailregex.com/](http://emailregex.com/) and read [https://davidcel.is/posts/stop-validating-email-addresses-with-regex/](https://davidcel.is/posts/stop-validating-email-addresses-with-regex/) – HouseInTheForest Aug 26 '17 at 17:49

2 Answers2

0

The code is not running because the pattern you are using is wrong in syntax you can use
/^([a-z]*)([A-Z]*)([0-9]*)(@)([a-zA-Z]*)([0-9]*).([a-zA-Z]*)([0-9]*).([a-zA-Z]*)([0-9]*)$/
You can visit https://regex101.com/ it explains every part of your regex to you.

ZE0TRON
  • 94
  • 6
0

It would work it you right pattern like this

 $pattern = "/^[a-zA-Z0-9_]*(@)[a-zA-Z]{2,9}.[a-zA-Z]{2,3}.[a-zA-Z]{2}$/";

Demo : https://eval.in/850480

Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109