Skip to content

Instantly share code, notes, and snippets.

@neu5ron
Last active July 2, 2023 10:40
Show Gist options
  • Save neu5ron/66078f804f16f9bda828 to your computer and use it in GitHub Desktop.
Save neu5ron/66078f804f16f9bda828 to your computer and use it in GitHub Desktop.
Valid domain name regex including internationalized domain name
domain_regex = r'(([\da-zA-Z])([_\w-]{,62})\.){,127}(([\da-zA-Z])[_\w-]{,61})?([\da-zA-Z]\.((xn\-\-[a-zA-Z\d]+)|([a-zA-Z\d]{2,})))'
#Python
domain_regex = '{0}$'.format(domain_regex)
valid_domain_name_regex = re.compile(domain_regex, re.IGNORECASE)
self.domain_name = self.domain_name.lower().strip().encode('ascii')
if re.match(valid_domain_name_regex, self.domain_name ):
return True
else:
return False
@hartescout
Copy link

Awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment