-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidators.py
More file actions
27 lines (22 loc) · 855 Bytes
/
Copy pathvalidators.py
File metadata and controls
27 lines (22 loc) · 855 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
import re
def validate_email(email):
pattern = r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
if re.fullmatch(pattern, email):
return True
return False
def validate_phone(phone):
pattern = r'^\+?[1-9]\d{1,14}$'
return bool(re.fullmatch(pattern, phone))
def validate_url(url):
pattern = r'^(https?://)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*/?$'
return bool(re.fullmatch(pattern, url))
def validate_username(username):
pattern = r'^[a-zA-Z0-9_]{5,15}$'
return bool(re.fullmatch(pattern, username))
if __name__ == '__main__':
emails = ['test@example.com', 'invalid-email', 'user@domain.org']
results = {email: validate_email(email) for email in emails}
print(results)
phones = ['+1234567890', '1234567']
results = {phone: validate_phone(phone) for phone in phones}
print(results)