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
| Attribute | Type | Description |
|---|---|---|
| message | string = Enter a valid domain name. | Enter a valid domain name. |
| ul | string = \u00a1-\uffff | Unicode letters range (must not be a raw string). |
| hostname_re | string | Regex pattern for the initial hostname label supporting Unicode characters. |
| domain_re | string | Regex pattern for intermediate domain labels with a maximum length of 63 characters per RFC 1034 sec. 3.1. |
| tld_no_fqdn_re | string | Regex pattern for the top-level domain label supporting Unicode or punycode without a trailing dot. |
| tld_re | string | Regex pattern for the top-level domain label that optionally allows a trailing dot. |
| ascii_only_hostname_re | string | Regex pattern for the initial hostname label restricted to ASCII alphanumeric characters and hyphens. |
| ascii_only_domain_re | string | Regex pattern for intermediate domain labels restricted to ASCII characters. |
| ascii_only_tld_re | string | Regex pattern for the top-level domain label restricted to ASCII characters with an optional trailing dot. |
| max_length | integer = 255 | Maximum allowed length for the entire domain name string, defaulting to 255 characters. |
Constructor
Signature
def DomainNameValidator(
**kwargs: dict
)
Parameters
| Name | Type | Description |
|---|---|---|
| **kwargs | dict | Arbitrary keyword arguments. Supports 'accept_idna' (boolean) to toggle Unicode support, and passes other arguments to the parent RegexValidator. |