domain¶
- validators.domain.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
- Parameters:
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](https://www.rfc-editor.org/rfc/rfc1034).
rfc_2782 – Domain name is of type service record. Allows optional underscores in the domain name. Ref: [RFC 2782](https://www.rfc-editor.org/rfc/rfc2782).
- Returns:
If value is a valid domain name. (ValidationError): If value is an invalid domain name.
- Return type:
(Literal[True])
- Raises:
(UnicodeError) – If value cannot be encoded into idna or decoded into utf-8.