diff --git a/src/validators/domain.py b/src/validators/domain.py index a8f991c4..c5eea7d4 100644 --- a/src/validators/domain.py +++ b/src/validators/domain.py @@ -42,7 +42,8 @@ def domain(value: str, /, *, rfc_1034: bool = False, rfc_2782: bool = False): # First character of the domain rf"^(?:[a-zA-Z0-9{'_'if rfc_2782 else ''}]" # Sub domain + hostname - + rf"(?:[a-zA-Z0-9-_]{{0,61}}[A-Za-z0-9{'_'if rfc_2782 else ''}])?\.)" + + rf"(?:[a-zA-Z0-9-{'_'if rfc_2782 else ''}]{{0,61}}" + + rf"[A-Za-z0-9{'_'if rfc_2782 else ''}])?\.)" # First 61 characters of the gTLD + r"+[A-Za-z0-9][A-Za-z0-9-_]{0,61}" # Last character of the gTLD diff --git a/tests/test_domain.py b/tests/test_domain.py index 4cd9c658..c8f5c4d9 100644 --- a/tests/test_domain.py +++ b/tests/test_domain.py @@ -11,8 +11,9 @@ ("value", "rfc_1034", "rfc_2782"), [ ("example.com", False, False), + ("exa_mple.com", False, True), ("xn----gtbspbbmkef.xn--p1ai", False, False), - ("underscore_subdomain.example.com", False, False), + ("underscore_subdomain.example.com", False, True), ("something.versicherung", False, False), ("someThing.versicherung.", True, False), ("11.com", False, False),