From dc7c34af4114f7d06515b3bff96128ad0dc66488 Mon Sep 17 00:00:00 2001 From: divakartika Date: Thu, 25 Feb 2021 10:01:44 +0000 Subject: [PATCH] Fix a bug to validations.py Closes: #1 Updated validations.py python script. Fixed the behavior of validate_user function in validations.py. --- Course3/Lab4/validations.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Course3/Lab4/validations.py b/Course3/Lab4/validations.py index b18de65a2e..0232538c8d 100644 --- a/Course3/Lab4/validations.py +++ b/Course3/Lab4/validations.py @@ -15,10 +15,13 @@ def validate_user(username, minlen): # Usernames can only use letters, numbers, dots and underscores if not re.match('^[a-z0-9._]*$', username): return False - # Usernames can't begin with a number - if username[0].isnumeric(): + # Usernames must begin with a letter + if username[0].isalpha() == False: return False return True - +print(validate_user("blue.kale", 3)) # True +print(validate_user(".blue.kale", 3)) # Formerly True, should be False +print(validate_user("red_quinoa", 4)) # True +print(validate_user("_red_quinoa", 4)) # Formerly True, should be False