From 85a7e4abe5288b92f1f301accf0e7321697df277 Mon Sep 17 00:00:00 2001 From: ramvittalkumar Date: Thu, 25 Feb 2021 13:04:12 +0000 Subject: [PATCH] Closes: #1 Updated validations.py python script. Fixed the behavior of validate_user function in validations.py. --- Course3/Lab4/validations.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Course3/Lab4/validations.py b/Course3/Lab4/validations.py index b18de65a2e..900d88af77 100644 --- a/Course3/Lab4/validations.py +++ b/Course3/Lab4/validations.py @@ -8,7 +8,7 @@ def validate_user(username, minlen): raise TypeError("username must be a string") if minlen < 1: raise ValueError("minlen must be at least 1") - + # Usernames can't be shorter than minlen if len(username) < minlen: return False @@ -18,7 +18,13 @@ def validate_user(username, minlen): # Usernames can't begin with a number if username[0].isnumeric(): return False + # Usernames can't start with . or _ + elif username[0]=='.' or username[0]=='_': + 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