PHP Validate Email Address

PHP Validate Email Address

Back in the day, you could validate email with javascript, Jquery, and php using regex. Regex will check the input and make sure it is what the web developer wants to accept. Back in the day is still valid today. Regex is still a good option to validate input.

But,today in the day, a web developer can keep on top of new and recent other built-in PHP functions which do the same thing. One such function is one which validates email addresses.

The function will check the email row from the database and make sure it comes out like blahbalh@example.com. It will not output garbage like aaaaa.com or anything not resembling a real email address. It does not go all the way and check if the address exists, but the output still looks good on the screen.

below is an example of the PHP built-in function to validate email addresses.

$command = "SELECT email from email_list ";
$result=mysqli_query($db, $command);
while ($row = mysqli_fetch_assoc($result)) {
$email_address = $row['email'];
if (filter_var($email_address, FILTER_VALIDATE_EMAIL)) {
echo " ".$email_address."; ";
}