Regular expressions · 15 / 15 Exercise Medium

Validate emails

Objective

Create a Python program that validates email addresses with a simple pattern.

Instructions

  • Read an integer n and then n addresses, one per line.
  • An address is valid if it has: a user made up of letters, numbers, dots or underscores; an @; a domain made up of letters or numbers; a dot; and an extension of 2 or more lower-case letters. The pattern is r"[A-Za-z0-9_.]+@[A-Za-z0-9]+\.[a-z]{2,}".
  • Use re.fullmatch.
  • Show Valid or Not valid for each address.
Input
4
ana@mail.com
ana@mail
@mail.com
ana.perez_1@empresa.es
Output
Valid
Not valid
Not valid
Valid

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise