validators.domain

Domain.

@validator
def domain( value: str, /, *, consider_tld: bool = False, rfc_1034: bool = False, rfc_2782: bool = False):

Return whether or not given value is a valid domain.

Examples:
>>> domain('example.com')
True
>>> domain('example.com/')
ValidationError(func=domain, args={'value': 'example.com/'})
>>> # Supports IDN domains as well::
>>> domain('xn----gtbspbbmkef.xn--p1ai')
True
Arguments:
  • value: Domain string to validate.
  • consider_tld: Restrict domain to TLDs allowed by IANA.
  • rfc_1034: Allows optional trailing dot in the domain name. Ref: RFC 1034.
  • rfc_2782: Domain name is of type service record. Allows optional underscores in the domain name. Ref: RFC 2782.
Returns:

(Literal[True]): If value is a valid domain name. (ValidationError): If value is an invalid domain name.

Raises:
  • (UnicodeError): If value cannot be encoded into idna or decoded into utf-8.