From 28be59e1cc6dccb4529e30a520c1206858540b22 Mon Sep 17 00:00:00 2001 From: ichlasul0899 Date: Thu, 25 Feb 2021 18:54:18 +0000 Subject: [PATCH] Closes: #1 Updated validations.py python script. Fixed teh behavior or validate_user function in validations.py --- Course3/Lab4/validatin.py | 4 ++++ Course3/Lab4/validations.py | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Course3/Lab4/validatin.py diff --git a/Course3/Lab4/validatin.py b/Course3/Lab4/validatin.py new file mode 100644 index 0000000000..5272c777e2 --- /dev/null +++ b/Course3/Lab4/validatin.py @@ -0,0 +1,4 @@ +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 diff --git a/Course3/Lab4/validations.py b/Course3/Lab4/validations.py index b18de65a2e..d23fb3db53 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 + #Username can't begin with special char + if not re.match('^[a-zA-Z]', username): + 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