Validating and Parsing Email Addresses

  • + 0 comments

    import email.utils import re noOfInp = int(input()) pattern = r'^[a-zA-Z]+[\w-.]+@[a-zA-Z]+.{1}[a-zA-Z]{1,3}$'

    def isValidEmail(username, mail): m = re.match(pattern, mail) if m: tupl = (username, mail) print(email.utils.formataddr(tupl))

    for i in range(noOfInp): inp = input() username = email.utils.parseaddr(inp)[0] mail = email.utils.parseaddr(inp)[1] isValidEmail(username, mail)