phppreg-matchereg

preg_match(): Unknown modifier '@'


I used to use my function with ereg (check that there's one @ symbol),

ereg("^[^@]{1,64}@[^@]{1,255}$", $email)

but now it is deprecated. Why I am getting an error preg_match(): Unknown modifier '@' when I fixed it to preg_match("^[^@]{1,64}@[^@]{1,255}$", $email)?


Solution

  • You need to add delimiters around your expression.

    preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $email)
    

    I strongly suggest to start reading about PCRE pattern syntax.