forked from dilinjer/validations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidations.py
More file actions
30 lines (27 loc) · 866 Bytes
/
validations.py
File metadata and controls
30 lines (27 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
def validate_user(username, minlen):
"""Checks if the received username matches the required conditions."""
if type(username) != str:
print("not a string")
raise TypeError("username must be a string")
if minlen < 1:
print("minlen is too short")
raise ValueError("minlen must be at least 1.")
if len(username) < minlen:
print("too short my dear..")
return False
if not username.isalnum():
print("bad choice of characters!")
return False
# Usernames can't begin with a number
if username [0].isnumeric():
print("You can't start with a number.")
return False
return True
def main():
minlen = 3;
username = input("Enter username \n")
if validate_user(username,minlen):
print("Welcome", username)
pass
main()