Show Errors After Leaving a Field
Write the code, see it run, pass the checks.
The problem
- medium
- Code
A registration form has text inputs labelled "Username" and "Age", in that order, and a "Register" button. Username needs at least 3 characters, not counting spaces at either end; otherwise its error is "Username must be at least 3 characters". Age must be a whole number from 18 to 120; otherwise its error is "Enter an age from 18 to 120". Don't show a field's error while someone is still typing in it for the first time: show it once they leave the field, or once they press Register. From then on it updates as they type. Show each error as text next to its field (outside the label). Pressing Register with no errors replaces the form with "Registered, Ada!" (with the trimmed username). Give the form noValidate, so the browser's own checks never get in the way.
Your code must pass
- No error shows while you first type
- Leaving a field shows its error
- A shown error updates as you type
- Register shows every error
- A valid form registers