Discussion about this post

User's avatar
Luiz Lopes's avatar

#VALID USERNAME

def is_valid_username(username):

return (5 <= len(username) <= 15 and username[0].isalpha() and username.isalnum())

while True:

print('5 to 15 characteres and must start with a letter')

prompt = input('Type your username here (or type "exit" to quit): ')

if prompt.lower() == "exit":

print("Exiting...")

break

if is_valid_username(prompt):

print('Valid username')

break

else:

print('Username invalid. Please try again.')

Expand full comment
Gabriel Ovidor's avatar

username = input('Write here your name: ')

def check_username_validity(username):

characters = len(username)

key_num = username.isalnum()

key_alpha = username[0].isalpha()

if (characters > 15) or (characters < 5):

print('Your username is invalid because it doesnt have the exact numbers right!')

elif key_num is not True:

print('Your username does not contain only alphanumerics.')

elif key_alpha is not True:

print('The first character of the username must be a letter.')

else:

print('Valid username')

check_username_validity(username)

Expand full comment
4 more comments...

No posts