From 626f72463578e70bb3ccb1378faa5e5fd11915a9 Mon Sep 17 00:00:00 2001 From: Reylian Anareka Date: Thu, 25 Feb 2021 13:17:17 +0000 Subject: [PATCH 1/2] i fix the regular expression code to check if the first letter is alphabetic only --- 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..80a9d76fa8 100644 --- a/Course3/Lab4/validations.py +++ b/Course3/Lab4/validations.py @@ -8,17 +8,20 @@ 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 # Usernames can only use letters, numbers, dots and underscores - if not re.match('^[a-z0-9._]*$', username): + if not re.match('^[a-z][a-z0-9._]*$', 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 From c632e3f67587181aa2984d6abcf1751d32e6a565 Mon Sep 17 00:00:00 2001 From: Reylian Anareka Date: Thu, 25 Feb 2021 13:19:55 +0000 Subject: [PATCH 2/2] Closes: #1 Updated validations.py python script. Fixed the behavior of validate_user function in validations.py --- Course3/Lab4/validations.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Course3/Lab4/validations.py b/Course3/Lab4/validations.py index 80a9d76fa8..7a1a2b71fe 100644 --- a/Course3/Lab4/validations.py +++ b/Course3/Lab4/validations.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 - + import re - + def validate_user(username, minlen): """Checks if the received username matches the required conditions.""" if type(username) != str: @@ -20,6 +20,7 @@ def validate_user(username, minlen): 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