Skip to content

Instantly share code, notes, and snippets.

@simonklee
Last active August 29, 2015 13:56
Show Gist options
  • Save simonklee/8842786 to your computer and use it in GitHub Desktop.
Save simonklee/8842786 to your computer and use it in GitHub Desktop.
Domain whitelist
import re
class DomainWhitelist(object):
url_re = re.compile(
r'([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6})',
re.IGNORECASE)
kogama_re = re.compile(
r'^(http[s]?://)?([a-z0-9-.]{2,8})?kogama.com(.br)?',
re.IGNORECASE)
def check(self, value):
for url in self.url_re.findall(value):
if not self.kogama_re.match(''.join(url)):
return False
return True
@simonklee
Copy link
Author

Yes and no. You wont be able to write a comment with the username "simon.kogama" in it. However, that is not something we can solve, since domain and user names follow some of the same rules.

We do however not run these validations on usernames directly. Usernames are upon creation checked versus a much stricter regex which limits the possibilities. You can create a username like this xxx.com, but that is about it.

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