[Tutor] Checking for Control Characters

Sheila King sheila@thinkspot.net
Sat, 6 Apr 2002 21:09:47 -0800


On Sat, 06 Apr 2002 21:04:41 -0800 (PST), Sean 'Shaleh' Perry wrote:
> >
> >
> > 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,
> >
>
>
> def validateInput(input): import string
>
> valid = string.letters + string.digits + '_' for char in input: if
> char not in valid: return 0 return 1
>
> validateInput('shaleh') # should be 1 validateInput('\tJim\r') #
> should be 0
>
>

Sean,

Tha's a little too restrictive. For example, you will notice from the 
list of 'not allowed' characters that I listed previously, that the 
single quote character is allowed. Also, the back quote, and the 
tilde, etc.

The instructions I've been given (by the person I'm writing this 
script for) are to NOT ALLOW certain characters. So, I'm trying to 
check for those.

In any case, I would still like to know the best way to check to 
determine whether a character is among the list \000-\037, \0177
which are the control characters I've been told to not allow.


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