11 lines
392 B
Python
11 lines
392 B
Python
import re
|
|
|
|
def validate_hostname(value):
|
|
value = value.strip().rstrip(".")
|
|
if len(value) > 253 or not value or any(
|
|
not re.fullmatch(r"[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?", label)
|
|
for label in value.split(".")
|
|
):
|
|
raise ValueError("Enter a hostname or FQDN using letters, digits, hyphens and dots (no URLs or commands).")
|
|
return value.lower()
|