#C11097. Email Address Validator

    ID: 40375 Type: Default 1000ms 256MiB

Email Address Validator

Email Address Validator

Given an email address as input, your task is to determine whether it is valid according to the following rules:

  • The email must contain exactly one @ symbol.
  • The local part (the part before the @) must consist only of lowercase letters and digits, and may include the characters . (dot), _ (underscore) and - (hyphen). It should not start or end with a dot and must not contain consecutive dots.
  • The domain part (the part after the @) must begin with lowercase letters or digits. It may include hyphens, but they cannot be at the beginning or end. The domain must include a period followed by at least two lowercase letters (the TLD). It can have multiple .tld parts.

Use regular expressions to perform most of the checks. If any check fails, output False; otherwise, output True.

Mathematically, if we denote the local and domain patterns in LaTeX as:

\(Local:\; R_{local} = ^[a-z0-9]+[a-z0-9._-]*[a-z0-9]+$\)

\(Domain:\; R_{domain} = ^[a-z0-9]+([a-z0-9-]*[a-z0-9]+)?(\.[a-z]{2,})+$\)

then an email \(E\) is valid if and only if \(E = local \ + \ "@" \ + \ domain\), the local part matches \(R_{local}\) (and does not contain consecutive dots), and the domain part matches \(R_{domain}\).

inputFormat

The input contains a single line representing an email address.

You can assume the email does not contain any leading or trailing spaces.

outputFormat

Output a single line: True if the email address is valid according to the rules, or False otherwise.

## sample
john.doe@example.com
True