applying a filter on a string in python -


i have user typing in username , want valid strings pass through, meaning characters in [a-za-z0-9]. pretty new python , unsure of syntax.

here's example of want in code, check through username , return false upon illegal character.:

def _checkinput(input):      char in input:           if !(char in [a-za-z0-9]):                return false      return true 

thanks!

you need isalnum:

>>> name = raw_input('enter name: ') enter name: foo_bar >>> name.isalnum() false >>> name = raw_input('enter name: ') enter name: foobar >>> name.isalnum() true 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -