How can I replace the eregi on this code with pregmatch?
$subemail=$_POST['emailadd'];
$regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{1,})*\.([a-z]{2,}){1}$";
if(!eregi($regex, $subemail)){
//do this
}
Why you don't use filter_var to validate email?
var_dump(filter_var('bob@example.com', FILTER_VALIDATE_EMAIL));
Simply add delimiters(I use /
) before and after your original regex and then add i
flags at the end.
if(!eregi( "/". $regex ."/i", $subemail)){
//do this
}
try the below code.
$regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
if (preg_match($regex, $email)) {
echo $email . \" is a valid email. We can accept it.\";
} else {
echo $email . \" is an invalid email. Please try again.\";
}