← Back to challenges

Basic E-Mail Validation

JavaScriptHardvalidationstringslogicregex

Instructions

Create a function that accepts a string, checks if it's a valid email address and returns either true or false, depending on the evaluation.

  • The string must contain an @ character.
  • The string must contain a . character.
  • The @ must have at least one character in front of it.
  • The . and the @ must be in the appropriate places.

If the string passes these tests, it's considered a valid email address.

Examples

validateEmail("@gmail.com") ➞ false

validateEmail("hello.gmail@com") ➞ false

validateEmail("gmail") ➞ false

validateEmail("hello@gmail") ➞ false

validateEmail("[email protected]") ➞ true

Notes

  • Check the Tests tab to see exactly what's being evaluated.
  • You can solve this challenge with RegEx, but it's intended to be solved with logic.
  • Solutions using RegEx will be accepted but frowned upon :(
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Online Shopping