Call validate
Lesson 6 of 8 in Coddy's Email validator using Python course.
We finished the validation function!
Now let's call it all from main function.
In Python, to create main function use,
if __name__ == "__main__":
# write code hereAnd write the code inside the if clause.
Challenge
EasyCreate a main function, in the function ask for input from the user and use the validate function on the input, print the output of validate.
Try it yourself
PERMITS_RECIEPENT = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._'
PERMITS_DOMAIN = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-'
def validate(email):
if not email.count('@') == 1:
return False
recipient_name = email.split('@')[0]
if len(recipient_name) > 24 or len(recipient_name) < 3:
return False
for c in recipient_name:
if c not in PERMITS_RECIEPENT:
return False
if '.' == recipient_name[0] or '.' == recipient_name[-1] or '_' == recipient_name[0] or '_' == recipient_name[-1]:
return False
domain_name = email.split('@')[1].split('.')[0]
if len(domain_name) > 12 or len(domain_name) < 3:
return False
for c in domain_name:
if c not in PERMITS_DOMAIN:
return False
top_level_domain_name = email.split('@')[1].split('.')[1]
if top_level_domain_name not in ['com', 'org', 'net', 'tech']:
return False
return True