users = ["admin", "root1", "John_Doe", "Alice", "Bob42"] badChar=False for user in users: for ch in user: if ('a' <= ch <='z') or ('A' <= ch <='Z') or ch == ' ': badChar=False else: badChar=True break if badChar == False and len(user) <= 20: print(user + " is Valid") else: print(user + " Error contain special character, space or digit !")