python-validators/validators

Support for RFC 1123 hostname validation

Opened this issue · 2 comments

🚀 Feature Request

Please consider adding support for validating hostnames against RFC 1123, which defines valid DNS hostnames. This would be helpful for use cases where strict compliance is needed (e.g., infrastructure tools, domain name validation, security filters).

✅ RFC 1123 Requirements Summary

RFC 1123 hostnames must:

  • Only include letters (A–Z, a–z), digits (0–9), and hyphens (-)
  • Not begin or end with a hyphen
  • Be ≤ 253 characters total
  • Have each label ≤ 63 characters
  • Cannot contain underscores or other special characters

This document has had many revisions. Please provide references to these requirements based on updated documents.

🧩 RFC 1123 Hostname Requirements Summary

📄 Source: RFC 1123 – Section 2.1 (Host Names and Numbers)

“The syntax of a legal Internet host name was specified in RFC-952.
One aspect of host name syntax is hereby changed: the restriction on the first character is relaxed to allow either a letter or a digit.
Host software MUST support this more liberal syntax.
Host software MUST handle host names of up to 63 characters and SHOULD handle host names of up to 255 characters.”

RFC 1123 § 2.1


✅ Summary of Requirements Derived from RFC 1123

Rule Defined or Modified in RFC 1123 Notes
Hostnames may begin with a letter or digit ✅ RFC 1123 § 2.1 RFC 1123 explicitly relaxes RFC 952 (which required starting with a letter).
Hostnames use letters, digits, and hyphens only (LDH rule) ✅ Inherited from RFC 952, reaffirmed by RFC 1123 RFC 1123 didn’t change the allowed character set.
No leading or trailing hyphen ✅ From RFC 952 § 1, still in effect RFC 1123 doesn’t alter this restriction.
Label length ≤ 63 characters ✅ RFC 1123 § 2.1 The RFC requires software to handle labels up to 63 characters.
Full name ≤ 255 characters ✅ RFC 1123 § 2.1 “SHOULD handle host names of up to 255 characters.”