Email Validator - Problem
You are given a string and need to validate if it represents a valid email format.
A valid email must satisfy all of the following conditions:
- Contains exactly one '@' symbol
- Has a domain part after the '@' (at least one character)
- Contains no spaces anywhere in the string
- Uses only valid characters: letters (a-z, A-Z), digits (0-9), dots (.), hyphens (-), underscores (_)
- Does not start or end with a dot
Return true if the email is valid, false otherwise.
Input & Output
Example 1 — Valid Email
$
Input:
email = "user@domain.com"
›
Output:
true
💡 Note:
Has exactly one '@' at position 4, domain 'domain.com' exists, no spaces, all characters are valid (letters, dot), doesn't start or end with dot
Example 2 — Invalid: Multiple @ Symbols
$
Input:
email = "user@@domain.com"
›
Output:
false
💡 Note:
Contains two '@' symbols, which violates the rule of exactly one '@' symbol
Example 3 — Invalid: Contains Spaces
$
Input:
email = "user @domain.com"
›
Output:
false
💡 Note:
Contains a space character before '@', which is not allowed in valid email format
Constraints
- 1 ≤ email.length ≤ 1000
- email consists of printable ASCII characters
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code