Looking for somewhere to host your site? Browse our PHP web hosts section!

Home > Code Snippets > Verify an email address is in the valid format using filter_var

Verify an email address is in the valid format using filter_var

Description

This built-in email validation function lets you make sure that an email address is in the proper format of someone@somedomain.tld without having to resort to using a regular expression. PHP 5.2.0 is required, and it's enabled by default.

The code

<?php
$email 
'someone@somedomain.tld';

if (
filter_var($emailFILTER_VALIDATE_EMAIL)) {
    
// A valid address
}
else {
    
// An invalid address
}
?>