Thanks guys! 
  I appreciate it....

Here is my code, which works,

*but..
*as noted in my comments, 
if * asdf*  is a racial slur,
then
*youasdf*
should NOT be allowed as a username, even if *youasdf *is somehow taken
 in another context, in a real name or word. User will have to pick another 
username.

What do I need to do the the reg ex to flag
*youasdf*
as a bad word?

Note, for now, I'm just testing with this in* layout.html* and will attempt 
the username thing after I get it working.

{{=IS_BAD()('youasdf')}}




# this import is required in web2py
import base64, re

#let's assume:
#  username can't contain spaces, just a-z and periods

# 'frig' is a very bad word
# 'sadf' is a racial slur


# so even if a person's name as frig, or asdf in it
# we will not let them use that.

# asdf    - is flagged as a bad username
# asdfyou - is flagged as a bad username
# youasdf - is NOT flagged a bad username, but IT SHOULD BE.
 
badlist = ['frig', 'asdf', 'etc']

BADWORDS = re.compile(r'|'.join(badlist))

class IS_BAD:
    def __init__(self,error_message='bad word is contained in username'):
        self.error_message = error_message
    def __call__(self,value):
        if BADWORDS.match(value):
            return (value,self.error_message)
        return (value, None)






-- 



Reply via email to