[Tutor] Checking for Control Characters

Sheila King sheila@thinkspot.net
Sat, 6 Apr 2002 20:57:16 -0800


I'm writing a cgi script right now, for changing passwords on an 
account.

I have to check my input, and the account's username is not allowed 
to have any of the following characters:

not_allowed = '!"#$%(),:;<>@[]|& '  #characters not allowed in 
usernames

This is no problem, and I'm basically checking this with a piece of 
code similar to the following:

    for char in username:
        if char in not_allowed:
            <do stuff for bad data entry>

And of course, that works fine.

However, I am also not supposed to permit any control characters in 
the username,
and was told the following:

Not allowed: control characters \000-\037 \0177

Now, I'm sure I could fiddle around with this, but I was hoping 
someone might have some advice or recommendations on a good way to 
proceed for checking for the control characters. Any and all advice 
welcome,

Thanks,

-- 
Sheila King
http://www.thinkspot.net/sheila/