From a5d11c0645ed2bb06093466672cba64d0181e242 Mon Sep 17 00:00:00 2001 From: John Kevin Francisco Date: Sun, 18 May 2025 11:18:25 +0000 Subject: [PATCH] Closes: #1 Updated validation.py python script. Fixed the behavior of validate_user function in validations.py --- Course3/Lab4/validations.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Course3/Lab4/validations.py b/Course3/Lab4/validations.py index b18de65a2e..a14cd6e79f 100644 --- a/Course3/Lab4/validations.py +++ b/Course3/Lab4/validations.py @@ -15,10 +15,16 @@ def validate_user(username, minlen): # Usernames can only use letters, numbers, dots and underscores if not re.match('^[a-z0-9._]*$', username): return False + # Make sure username starts with alphanumeric + if not re.match('^[a-zA-Z]*$', username[0]): + return False # Usernames can't begin with a number if username[0].isnumeric(): return False return True - +print(validate_user("blue.kale", 3)) # True +print(validate_user(".blue.kale", 3)) # Currently True, should be False +print(validate_user("red_quinoa", 4)) # True +print(validate_user("_red_quinoa", 4)) # Currently True, should be False