Magicsheet logo

Find Users With Valid E-Mails

Easy
53.3%
Updated 6/1/2025

Find Users With Valid E-Mails

1. What is this problem about?

The Find Users With Valid E-Mails interview question is a data validation task in SQL. You are given a Users table and need to find users whose email addresses follow a specific, strict format:

  1. Must start with a letter.
  2. Can contain letters (upper/lower), digits, underscores _, periods ., and dashes -.
  3. Must end with the domain @leetcode.com.

2. Why is this asked in interviews?

Companies like Meta and Google ask the Find Users With Valid E-Mails coding problem to test a candidate's proficiency with Regular Expressions (Regex) in SQL. Data cleaning and validation are major parts of data engineering, and the ability to write robust regex patterns is essential for ensuring data quality. It evaluations your attention to detail regarding character classes and boundaries.

3. Algorithmic pattern used

This problem follows the SQL Regex Matching pattern.

  • Pattern Construction: ^[A-Za-z][A-Za-z0-9_.-]*@leetcode[.]com$
  • Breakdown:
    • ^: Start of string.
    • [A-Za-z]: First character must be a letter.
    • [A-Za-z0-9_.-]*: Subsequent characters can be letters, digits, underscores, dots, or dashes.
    • @leetcode[.]com$: Must end exactly with the specified domain. (Note the [.] to treat the period literally).

4. Example explanation

  • julia@leetcode.com: Valid.
  • 123_abc@leetcode.com: Invalid (starts with digit).
  • abc-def.ghi_123@leetcode.com: Valid.
  • abc@gmail.com: Invalid (wrong domain).
  • abc@leetcode?com: Invalid (contains ?).

5. Common mistakes candidates make

  • Escaping issues: Forgetting that . is a wildcard in regex and needs to be escaped or put in a character class [.] to match a literal period.
  • Character classes: Missing one of the allowed symbols (like - or _).
  • Case sensitivity: Not ensuring the pattern handles both uppercase and lowercase letters if the database is case-sensitive.

6. Interview preparation tip

Practice SQL regex syntax for different dialects (MySQL REGEXP, PostgreSQL ~, etc.). Although the logic is similar, the exact symbols for word boundaries or character classes can vary slightly. This is a common Database interview pattern requirement.

Similar Questions