Validate Email Address
Updated
Problem statement
You are given a string email. Return true if it follows all of these rules, and false otherwise:
- It contains exactly one
@. - The local part is the text before
@. It is nonempty and uses only lowercase letters, digits, dots, underscores, and hyphens. - The domain is the text after
@. It has at least two nonempty labels separated by dots. - Each domain label uses only lowercase letters, digits, and hyphens. A label cannot begin or end with a hyphen.
These are simple rules made for this exercise. They are not the full RFC email standard.
Function
isValidEmail(email: String) → booleanExamples
Example 1
email = "dev.team@example.com"return = trueThe address has one @, a valid local part, and two valid domain labels.
Example 2
email = "userexample.com"return = falseThe address does not contain an @.
Example 3
email = "user@-example.com"return = falseThe first domain label begins with a hyphen.
Constraints
1 <= email.length <= 10^5.emailcontains ASCII characters.
More Accenture interview questions
- Nearest Composite NumberOA · Seen Sep 2026
- Minimum Password IncrementsOA · Seen Sep 2026
- Reduce a Number to One DigitOA · Seen Sep 2026
- Candy DistributionOA · Seen Sep 2026
- Customers Who Never OrderedOA · Seen Sep 2026
- Economical TripOA · Seen Sep 2026
- Coin ChangeOA · Seen Sep 2026
- Closest Rhyming WordOA · Seen Aug 2026
- Array Leader ElementsOA · Seen Nov 2025
- Alternating Index Square SumONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
- Count Valid Space-Delimited WordsVisa · OAVisa interview questions
- Scale Ingredient QuantitiesUpstart · OAUpstart interview questions
- Is This Date a Weekend?Salesforce · OASalesforce interview questions
- FIX Message ReconciliationVirtu Financial · OAVirtu Financial interview questions
- IPv4 Address ClassificationRippling · OARippling interview questions
- Generate Table of ContentsJP Morgan Chase · OAJP Morgan Chase interview questions
- Highest-Ranked University by CountryAgoda · OAAgoda interview questions
- Counterfeit CurrencyBox · OABox interview questions
- Convert Snake Case Variables to Camel CaseRamp · OARamp interview questions