Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DNSCheckValidation.php

function DNSCheckValidation::isValid

Overrides EmailValidation::isValid

File

vendor/egulias/email-validator/src/Validation/DNSCheckValidation.php, line 75

Class

DNSCheckValidation

Namespace

Egulias\EmailValidator\Validation

Code

public function isValid(string $email, EmailLexer $emailLexer) : bool {
    // use the input to check DNS if we cannot extract something similar to a domain
    $host = $email;
    // Arguable pattern to extract the domain. Not aiming to validate the domain nor the email
    if (false !== ($lastAtPos = strrpos($email, '@'))) {
        $host = substr($email, $lastAtPos + 1);
    }
    // Get the domain parts
    $hostParts = explode('.', $host);
    $isLocalDomain = count($hostParts) <= 1;
    $isReservedTopLevel = in_array($hostParts[count($hostParts) - 1], self::RESERVED_DNS_TOP_LEVEL_NAMES, true);
    // Exclude reserved top level DNS names
    if ($isLocalDomain || $isReservedTopLevel) {
        $this->error = new InvalidEmail(new LocalOrReservedDomain(), $host);
        return false;
    }
    return $this->checkDns($host);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal