Files
mdb/mdb/validators.py
T
2026-03-19 02:25:30 +01:00

14 lines
502 B
Python

from django.core.validators import RegexValidator
import re
# http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
hostname_re = re.compile(r"^(?!-)[-a-z0-9]+(?<!-)$", re.IGNORECASE)
validate_hostname = RegexValidator(
regex=hostname_re, message="Enter a valid hostname", code="invalid"
)
macaddr_re = re.compile(r"^([0-9A-F]{2}[:]){5}([0-9A-F]{2})$", re.IGNORECASE)
validate_macaddr = RegexValidator(
regex=macaddr_re, message="Enter a valid MAC address", code="invalid"
)