php

How to Validate an Email Address in PHP

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 = "[email protected]";

	// 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
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

One thought on “How to Validate an Email Address in PHP

  • Albert Bollenbach

    Where do I enter the validation code provided for registering?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *