Created
September 17, 2015 11:45
-
-
Save gregpinero/39e1390434cbc3656f97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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