
Build a modern sign-up form as a component. The form should collect the user’s email address and password, and include robust email validation. When the user submits the form, validate the inputs and provide clear feedback if any field is invalid. If all validations pass, display a success message instead of the form. Before you build this React sign-up form, MDN’s guide to client-side form validation is a useful refresher.
React Sign-Up Form: Requirements
- Render a sign-up form with the following fields:
- Email address (required, must be a valid email format)
- Password (required, at least 8 characters)
- Validate the email using a standard regular expression (use the provided
EMAIL_REGEX)
- Display real-time error messages below each field as the user types (not before the user has typed anything):
- Invalid email: e.g. “Enter a valid email address.”
- Short password: e.g. “Password must be at least 8 characters.”
- Disable the submit button until both fields are valid
- On successful submit, display a “Sign up successful!” message instead of the form
- Do not use any third-party form libraries
Accessibility
- Each input must be labeled and accessible by keyboard and screen reader
- Errors must be associated with the corresponding input
Example
- Typing an invalid email immediately shows an error message.
- Typing a short password (less than 8 chars) shows a password error.
- The submit button remains disabled until both fields are valid.
- Upon successful submission, "Sign up successful!" is shown.
How your solution is tested
The tests type into your fields and read the text on the screen, like a real user would. You don’t need test ids, specific class names, or an exact HTML structure. They only check that:
- The inputs have a label,
aria-label, placeholder, or name containing “Email” and “Password”.
- The email error contains the word “valid” (e.g. “Enter a valid email address”) and the password error mentions “8”.
- The submit button’s text includes “Sign Up” (or “Submit” / “Register”) and is
disabled until both fields are valid.
- After submitting, the text “Sign up successful!” is shown and the email/password fields are gone. Capitalization doesn’t matter.