Skip to content

Instantly share code, notes, and snippets.

@gregpinero
Created September 17, 2015 11:45
Show Gist options
  • Save gregpinero/39e1390434cbc3656f97 to your computer and use it in GitHub Desktop.
Save gregpinero/39e1390434cbc3656f97 to your computer and use it in GitHub Desktop.
class UserNameValidator(object):
"""A simple user name validator to prohibit banned words"""
not_allowed = set(['parrot','dog','kitten','ibis',])
substitutions = {'1':'i','0':'o','7':'t'}
def is_valid(self, name):
name = name.lower()
#Substitute values as needed in name
for find,replace in UserNameValidator.substitutions.items():
name = name.replace(find, replace)
if name in UserNameValidator.not_allowed:
return False
return True
if __name__=='__main__':
validator = UserNameValidator()
test_list = ['ibis','ib1s','1bis','1b1s','k1t7en','goodname']
for test in test_list:
print test, validator.is_valid(test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment