Username validation in python
Username validation in python
Have the function CodelandUsernameValidation(str) take the str parameter being passed and determine if the string is a valid username according to the following rules:
1. The username is between 4 and 25 characters.
2. It must start with a letter.
3. It can only contain letters, numbers, and the underscore character.
4. It cannot end with an underscore character.
If the username is valid then your program should return the string true, otherwise, return the string false.
Farjanul Nayem Answered question July 22, 2022
import string def CodelandUsernameValidation(strParam): match=string.ascii_letters + string.digits + '_' if not all([x in match for x in strParam]): return False if not (len(strParam) >=4 and len(strParam) <=25): return False if not strParam[0].isalpha(): return False if strParam[-1:] == '_': return False return True # keep this function call here print(CodelandUsernameValidation(input()))
Farjanul Nayem Answered question July 22, 2022