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?
Just use:
$pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i";
Maybe using
filter_var($email, FILTER_VALIDATE_EMAIL);
Would be an easier approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With