Practice ยท 1 of 1
Validate a Signup Form
Elements are provided: form, usernameInput (a text field), emailInput, and errorBox. Build the submit flow:
1. Add a submit listener to form that calls event.preventDefault() first.
2. Read the username; if its trimmed length is under 3, set errorBox.textContent to a helpful message and stop.
3. Read the email; if it does not include "@", show an error the same way.
4. Otherwise clear errorBox.textContent and log Welcome, <username>.
Then simulate: submit with username "ab" (too short), then submit with a valid username and email โ and log after each.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Forms: Reading Input and Validating โ Practice