Jan Walraven
DevOps



Categories:
  • Arduino (2)
  • CSS (3)
  • Docker (10)
  • ESXi (1)
  • Git (4)
  • Javascript (6)
  • Linux (31)
  • Mac (6)
  • Magento (4)
  • Mysql (13)
  • PHP (9)
  • Zend framework 2 (9)
  • Posted on July 25, 2013

    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:

    • allow: Defines which type of domain names are accepted. This option is used in conjunction with the hostname
      option to set the hostname validator. For more information about possible values of this option, look at
      Hostname and possible ALLOW* constants. This option defaults to
      ALLOW_DNS.
    • deep: Defines if the servers MX records should be verified by a deep check. When this option is set to
      TRUE then additionally to MX records also the A, A6 and AAAA records are used to verify if the server
      accepts emails. This option defaults to FALSE.
    • domain: Defines if the domain part should be checked. When this option is set to FALSE, then only the
      local part of the email address will be checked. In this case the hostname validator will not be called. This
      option defaults to TRUE.
    • hostname: Sets the hostname validator with which the domain part of the email address will be validated.
    • mx: Defines if the MX records from the server should be detected. If this option is defined to TRUE then
      the MX records are used to verify if the server accepts emails. This option defaults to FALSE.
    
    $validator = new ZendValidatorEmailAddress();
    $validator->setOptions(array('domain' => false));