Advertisement
horozov86

Email Validator

Jun 2nd, 2023 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. from exceptions import MustContainAtSymbolError, NameTooShortError, InvalidDomainError
  2.  
  3. possible_domains = [".com", ".bg", ".org", ".net"]
  4.  
  5. while True:
  6.     data = input()
  7.     if data == "End":
  8.         break
  9.    
  10.     email = data
  11.    
  12.     email_prats = email.split("@")
  13.     if len(email_prats) != 2:
  14.         raise MustContainAtSymbolError("Email must contain @")
  15.        
  16.     name, second_part = email_prats
  17.    
  18.     if len(name) <= 4:
  19.         raise NameTooShortError(- "Name must be more than 4 characters")
  20.        
  21.     domain = f".{second_part.split('.')[-1]}"
  22.    
  23.     if domain not in possible_domains:
  24.         raise InvalidDomainError(f"Domain must be one of the following: {', '.join(possible_domains)}")
  25.        
  26.        
  27.     print("Email is valid")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement