Advertisement
Guest User

m05_ls5_min_task02

a guest
Jan 16th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #!/usr/bin/python3
  2. """
  3. Написати програму яка запитує у користувача його email адресу, та
  4. перевіряє чи це коректна адреса. Тобто чи задана стрічка відповідає
  5. вимогам електронної адреси.
  6. ---------------------------
  7. Simplified rules are used for verification:
  8. - uppercase and lowercase Latin letters A to Z and a to z;
  9. - digits 0 to 9;
  10. - dot ., provided that it is not the first or last character unless quoted
  11. - hyphen -, provided that it is not the first or last character.
  12. """
  13. import re
  14. answer = input('Please enter your email address: ')
  15.  
  16. regex = re.compile(
  17. """
  18. ^[A-Z0-9]{1}[A-Z0-9.-]*[A-Z0-9]{1} #Check local-part email
  19. @
  20. [A-Z0-9]{1}[A-Z0-9.-]*[A-Z0-9]{1} #Check domain name part email
  21. \.[A-Z]{2,}
  22. """ , re.I|re.X)
  23.  
  24. email = re.search(regex, answer)
  25.  
  26. if email:
  27. print(f'Your email {email[0]} is correct')
  28. else:
  29. print('Your email is incorrect')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement