-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path02. Email Validator.py
More file actions
36 lines (25 loc) · 879 Bytes
/
02. Email Validator.py
File metadata and controls
36 lines (25 loc) · 879 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
31
32
33
34
35
36
class NameTooShortError(Exception):
""" Name less than or equal to 4 characters"""
pass
class MustContainAtSymbolError(Exception):
''' Email does not have @ '''
pass
class InvalidDomainError(Exception):
''' the domain is different than .com, .org... '''
pass
email = input()
while email != "End":
good_email = True
if '@' in email:
if len(email.split('@')[0]) <= 4:
good_email = False
raise NameTooShortError("Name must be more than 4 characters")
else:
good_email = False
raise MustContainAtSymbolError("Email must contain @")
if email.split('.')[-1] not in ['com', 'bg', 'org', 'net']:
good_email = False
raise InvalidDomainError("Domain must be one of the following: .com, .bg, .org, .net")
if good_email:
print("Email is valid")
email = input()