Repository navigation
Expand file tree
/
Copy pathvalidation.py
More file actions
83 lines (59 loc) · 1.91 KB
/
Copy pathvalidation.py
File metadata and controls
83 lines (59 loc) · 1.91 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import requests
def get_id():
while True:
user_id = input("Enter ID: ").strip()
if not user_id:
print("ID cannot be empty.")
continue
if not user_id.isdigit():
print("ID must contain digits only.")
continue
break
return user_id
def get_name():
while True:
name = input("Enter name: ").strip()
if not name:
print("Name cannot be empty.")
continue
if not all(word.isalpha() for word in name.split()):
print("Name must contain letters and spaces only.")
continue
break
return name
def get_phone():
while True:
phone = input("Enter phone number: ").strip()
if not phone:
print("Phone number cannot be empty.")
continue
if not phone.isdigit():
print("Phone number must contain digits only.")
continue
if len(phone) != 10:
print("Phone number must be 10 digits only")
continue
break
return phone
def get_email():
while True:
email = input("Enter email: ")
if not email:
print("Email cannot be empty.")
continue
if "@" not in email or "." not in email:
print("Please enter a valid email.")
continue
break
return email
def handle_error(e):
if isinstance(e, requests.exceptions.Timeout):
print("Request timed out.")
elif isinstance(e, requests.exceptions.ConnectionError):
print("Could not connect to the API.")
elif isinstance(e, requests.exceptions.HTTPError):
print("HTTP error:", e)
elif isinstance(e, requests.exceptions.RequestException):
print("Request error:", e)
else:
print("Unexpected error:", e)