FREE Web Template Download
HTML CSS JAVASCRIPT SQL PHP BOOTSTRAP JQUERY ANGULARJS TUTORIALS REFERENCES EXAMPLES Blog
 

PHP filter-VALIDATE_EMAIL Filter

PHP Filter Reference PHP Filter Reference

Example

Check if the variable $email is a valid email address:

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

if (!filter-var($email, filter-VALIDATE_EMAIL) === false) {
  echo("$email is a valid email address");
} else {
  echo("$email is not a valid email address");
}
?>
Run example »

Definition and Usage

The filter-VALIDATE_EMAIL filter validates an e-mail address.


More Examples

The example below both sanitizes and validates an email address:

Example 1

First remove all illegal characters from the $email variable, then check if it is a valid email address:

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

// Remove all illegal characters from email
$email = filter-var($email, filter-SANITIZE_EMAIL);

// Validate e-mail
if (!filter-var($email, filter-VALIDATE_EMAIL) === false) {
    echo("$email is a valid email address");
} else {
    echo("$email is not a valid email address");
}
?>
Run example »

PHP Filter Reference PHP Filter Reference