Jan Walraven
DevOps



Menu
Categories:
Posted on

ZendValidatorEmailAddress allows you to validate an email address. The validator first splits the email address on local-part @ hostname and attempts to match these against known specifications for email addresses and hostnames.


$validator = new ZendValidatorEmailAddress();
if ($validator->isValid($email)) {
    // email appears to be valid
} else {
    // email is invalid; print the reasons
    foreach ($validator->getMessages() as $message) {
        echo "$messagen";
    }
}

Options for validating EmailAddresses

ZendValidatorEmail supports several options which can either be set at initiation, by giving an array with the related options, or afterwards, by using setOptions().The following options are supported:


$validator = new ZendValidatorEmailAddress();
$validator->setOptions(array('domain' => false));