Validate Email Address in PHP

Description: Simple function for checking if an email address is in the proper format.
Tested Platform: PHP 7+
Language: PHP
// Validate email address and optionally checks validity when local 
// part may contain unicode characters.
// Requires PHP 7.1+ due to use of FILTER_FLAG_EMAIL_UNICODE

function isValidEmail($emailAddress, $unicodeSupported = true) {
    if ($unicodeSupported === true) {
        return (filter_var($emailAddress, FILTER_VALIDATE_EMAIL, FILTER_FLAG_EMAIL_UNICODE) !== false);

    return (filter_var($emailAddress, FILTER_VALIDATE_EMAIL) !== false);

Posted: March 18, 2023

Return to the snippets listing