You are here: Home / Topics / How to validate Email in PHP?

How to validate Email in PHP?

Filed under: PHP on 2023-04-16 07:46:15

In this tutorial, we are going to see how to validate an email address in PHP. Validating an email address is an action required before submitting the form. It checks if the user has provided a valid email address. Here is the easiest and most effective way to validate an email address in PHP.

filter_var() function in PHP provides a simple way to validate emails. Use FILTER_VALIDATE_EMAIL filter to validate the email address in PHP. filter_var() function returns the filtered data on success, or FALSE on failure.
 

How to Validate an Email Address in PHP

 

<?php
 $email = "example@abcd.com";

 // Email Validation
 if(filter_var($email, FILTER_VALIDATE_EMAIL)){
   echo "Email address is valid";
 }else{
   echo "Email address is not valid";
 }
?>

Output

Email address is valid

About Author:
Y
Yashika     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.