We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fce5976 commit 8dba0dfCopy full SHA for 8dba0df
Course3/Lab4/validations.py
@@ -0,0 +1,24 @@
1
+#!/usr/bin/env python3
2
+
3
+import re
4
5
+def validate_user(username, minlen):
6
+ """Checks if the received username matches the required conditions."""
7
+ if type(username) != str:
8
+ raise TypeError("username must be a string")
9
+ if minlen < 1:
10
+ raise ValueError("minlen must be at least 1")
11
12
+ # Usernames can't be shorter than minlen
13
+ if len(username) < minlen:
14
+ return False
15
+ # Usernames can only use letters, numbers, dots and underscores
16
+ if not re.match('^[a-z0-9._]*$', username):
17
18
+ # Usernames can't begin with a number
19
+ if username[0].isnumeric():
20
21
+ return True
22
23
24
0 commit comments