Command Palette

Search for a command to run...

Hectal
Phase 9: Events
JavaScript · Exercise 6 of 6 Previous
Intermediate

A sign-up form with your own validation

The form has novalidate, so the browser won't block it: your submit listener does the checking. On submit, always call preventDefault(), then check each field and write a message into its error paragraph (or empty it when the field is fine):

- #err-name: the name is empty.

- #err-email: the email is empty or not a valid email (use the field's validity).

- #err-password: the password has fewer than 8 characters.

- #err-confirm: the confirmation doesn't match the password.

If everything is valid, show Welcome, <name>! in #result (for example Welcome, Asha!). If anything is invalid, #result must be empty.

What Check tests

  1. Submitting doesn't reload the page
  2. An empty form shows name, email and password errors
  3. A badly written email is reported
  4. Different passwords are reported
  5. A short password is reported
  6. Valid data shows the welcome and clears every error

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.