Email Address Validator

Difficulty: Medium · Topics: String Parsing, Validation, Regex · Acceptance: 12.5% of 8 submissions

Difficulty: Medium  |  Tags: Regex, Validation, String Parsing

Description

Given a string, determine if it is a valid email address. The input may optionally include a display name in the format "Display Name ".

Implement:

isValidEmail(email) → boolean

Examples

Example 1:

Input:  "[email protected]"
Output: true

Example 2:

Input:  "Alice Smith <[email protected]>"
Output: true

Example 3:

Input:  "invalid-email"
Output: false

Example 4:

Input:  "[email protected]"
Output: false

Example 5:

Input:  "[email protected]"
Output: true

Example 6:

Input:  "@domain.com"
Output: false

Rules

  • Extract email from <...> if display name format is used.
  • Must have exactly one @.
  • Local part: starts with alphanumeric or +/-, can contain !#$%&'*+/=?^_{|}~..
  • Domain: valid hostname with 2-22 char TLD.
  • Total length between 4 and 256 characters.
  • Constraints

    ---

    ## Pagination

    Practice this problem

    Related problems