Validate an Email

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code

A sign-up form has a text input labelled "Email" and a "Sign up" button. When it's submitted (by the button or by pressing Enter), stop the page from reloading. If the email has no "@", or nothing before or after it, show "Enter a valid email address". Otherwise replace the form with "Thanks, " and the email, e.g. "Thanks, ada@example.com!". Keep the input type="text", so your own check runs rather than the browser's.

Your code must pass

  • An invalid email shows an error
  • A valid email shows the thanks message
  • Pressing Enter submits too