How to Validate an Email Address Using PHP

PHP










Email Address





In this article, we show how to validate an email address using PHP.

This is to make sure that the email that a user enters into an email text box is actually a valid email address.

PHP has a built-in function, filter_var() function, to check for email validation.

PHP Code

The PHP code to validate an email is shown below.

We create a variable named $email. We set to an example email.

We then create an if statement that if the filter_var() function with the $email as one of its parameters is true (not false), then it is a valid email address. Otherwise, it's an invalid email address.

It's really easy to validate an email address in PHP because it has a built-in function that checks for validation.


Related Resources

How to Retrieve Data From a MySQL Database Using AJAX and PHP

HTML Comment Box is loading comments...