Simple regex to validate email address in php. Validate email address in php regex while submitting form.
$email_regex = "/([a-z0-9_]+|[a-z0-9_]+\.[a-z0-9_]+)@(([a-z0-9]|[a-z0-9]+\.[a-z0-9]+)+\.([a-z]{2,4}))/i";
if(!preg_match($email_regex, $email)) {
echo "Invalid Email Address";
}
else {
echo "Valid Email Address";
}
$email_regex = "/([a-z0-9_]+|[a-z0-9_]+\.[a-z0-9_]+)@(([a-z0-9]|[a-z0-9]+\.[a-z0-9]+)+\.([a-z]{2,4}))/i";
if(!preg_match($email_regex, $email)) {
echo "Invalid Email Address";
}
else {
echo "Valid Email Address";
}
No comments:
Post a Comment