Skip to main content

DomainNameValidator

This class provides validation for domain names using regular expressions to ensure compliance with standard naming conventions and length requirements. It supports both standard ASCII-only domains and Internationalized Domain Names (IDNA) through configurable Unicode character support. The validator enforces a maximum length of 255 characters and verifies the structure of hostnames, domain labels, and top-level domains.

Attributes

AttributeTypeDescription
messagestring = Enter a valid domain name.Enter a valid domain name.
ulstring = \u00a1-\uffffUnicode letters range (must not be a raw string).
hostname_restringRegex pattern for the initial hostname label supporting Unicode characters.
domain_restringRegex pattern for intermediate domain labels with a maximum length of 63 characters per RFC 1034 sec. 3.1.
tld_no_fqdn_restringRegex pattern for the top-level domain label supporting Unicode or punycode without a trailing dot.
tld_restringRegex pattern for the top-level domain label that optionally allows a trailing dot.
ascii_only_hostname_restringRegex pattern for the initial hostname label restricted to ASCII alphanumeric characters and hyphens.
ascii_only_domain_restringRegex pattern for intermediate domain labels restricted to ASCII characters.
ascii_only_tld_restringRegex pattern for the top-level domain label restricted to ASCII characters with an optional trailing dot.
max_lengthinteger = 255Maximum allowed length for the entire domain name string, defaulting to 255 characters.

Constructor

Signature

def DomainNameValidator(
**kwargs: dict
)

Parameters

NameTypeDescription
**kwargsdictArbitrary keyword arguments. Supports 'accept_idna' (boolean) to toggle Unicode support, and passes other arguments to the parent RegexValidator.