Sign-Up Form
Build a sign-up form in HTML, CSS and JavaScript: four fields, a Sign Up button, and a request to the server once the form is valid.
The starter's script.js provides submitForm(values), a stand-in for the endpoint: it resolves with a message after a short delay, or rejects with an Error when the server refuses the form (a few usernames are taken, and it re-checks every rule).
Requirements
- Username: at least 4 characters, letters and digits only.
- Email: a plausible address; a simple check is enough.
- Password: at least 6 characters.
- Confirm password: must match the password.
- Clicking Sign Up, or pressing Enter in any field, submits the form.
- Every input has a visible label that focuses it when clicked, the right
type, and a visible focus ring. - State each rule with a native validation attribute where one exists, and in JavaScript where none does.
- Choose when to validate (while typing, on blur, on submit), but an invalid submit must show every failing field's message beside or below it, connect each message to its field for screen readers, and move focus to the first invalid field.
- While the request is out the button is disabled, so a second click cannot send a second request. Show the server's message under the button on failure and a success message on success.
Hints
Hint 1
Put novalidate on the form and the browser stops showing its own one-bubble-at-a-time messages — but every required, minlength, pattern and type="email" still fills in input.validity. Read the flags; write your own text.
Hint 2
aria-describedby on the input, pointing at the error paragraph's id, is the whole screen-reader story, plus aria-invalid="true" while the message shows. Keep the paragraph in the DOM when empty so the id always resolves.
Hint 3
Validate a field on blur the first time and on every keystroke once it has shown an error; validate everything on submit. Only the confirm field needs JavaScript for its rule, and it must re-run when the password changes.
Asked at
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.