How to Validate Email in PHP

Email validation is a required action before submitting the user input in the server-side. It checks whether the user has provided a valid email address. Here’s the absolute easiest and effective way to validate an email address using PHP.

The filter_var() function in PHP, provides an easy way for email validation. Use FILTER_VALIDATE_EMAIL filter to validate email address in PHP. The filter_var() function returns the filtered data on success, or FALSE on failure.

$email "john.codex@example.com";

// Validate email
if(filter_var($emailFILTER_VALIDATE_EMAIL)){
    echo 
"$email is a valid email address";
}else{
    echo 
"$email is not a valid email address";
}

Leave a reply

keyboard_double_arrow_up