src/Hostname.php
private static function myValidateDomainPart(string $domainPart, ?string &$error): bool
    {
        if ($domainPart === '') {
            $error = 'Part of domain "' . $domainPart . '" is empty.';

            return false;
        }

        if (strlen($domainPart) > 63) {
            $error = 'Part of domain "' . $domainPart . '" is too long: Maximum allowed length is 63 characters.';

            return false;
        }

        if (preg_match('/[^a-zA-Z0-9-]/', $domainPart, $matches)) {
            $error = 'Part of domain "' . $domainPart . '" contains invalid character "' . $matches[0] . '".';

            return false;
        }

        if (substr($domainPart, 0, 1) === '-') {
            $error = 'Part of domain "' . $domainPart . '" begins with "-".';

            return false;
        }

        if (substr($domainPart, -1) === '-') {
            $error = 'Part of domain "' . $domainPart . '" ends with "-".';

            return false;
        }

        return true;
    }
private static function myValidateDomainPart(string $domainPart, ?string &$error): bool
    {
        if ($domainPart === '') {
            $error = 'Part of domain "' . $domainPart . '" is empty.';

            return false;
        }

        if (strlen($domainPart) > 63) {
            $error = 'Part of domain "' . $domainPart . '" is too long: Maximum allowed length is 63 characters.';

            return false;
        }

        if (preg_match('/[^a-zA-Z0-9-]/', $domainPart, $matches)) {
            $error = 'Part of domain "' . $domainPart . '" contains invalid character "' . $matches[0] . '".';

            return false;
        }

        if (substr($domainPart, 0, 1) === '-') {
            $error = 'Part of domain "' . $domainPart . '" begins with "-".';

            return false;
        }

        if (substr($domainPart, -1) === '-') {
            $error = 'Part of domain "' . $domainPart . '" ends with "-".';

            return false;
        }

        return true;
    }
private static function myValidateDomainPart ( string $ domainPart , ? string & $ error ) : bool { if ( $ domainPart === '' ) { $ error = 'Part of domain "' . $ domainPart . '" is empty.' ; return false ; } if ( strlen ( $ domainPart ) > 63 ) { $ error = 'Part of domain "' . $ domainPart . '" is too long: Maximum allowed length is 63 characters.' ; return false ; } if ( preg_match ( '/[^a-zA-Z0-9-]/' , $ domainPart , $ matches ) ) { $ error = 'Part of domain "' . $ domainPart . '" contains invalid character "' . $ matches [ 0 ] . '".' ; return false ; } if ( substr ( $ domainPart , 0 , 1 ) === '-' ) { $ error = 'Part of domain "' . $ domainPart . '" begins with "-".' ; return false ; } if ( substr ( $ domainPart , - 1 ) === '-' ) { $ error = 'Part of domain "' . $ domainPart . '" ends with "-".' ; return false ; } return true ; }
Validates a domain part.

@param string      $domainPart The domain part.
@param string|null $error      The error text if validation was not successful, undefined otherwise.

@return bool True if validation was successful, false otherwise.
Validates a domain part .