Form Validation
Solidify your knowledge of Forms in React by solving this problem.
Jetha Lal is working on a new component for login, where he is supposed to do these basic validations.
- Username should be at least 5 characters long
- Password should be at least 8 characters long
- Button should be disabled if any of the above validation fails
Help him complete this component using useState
and useEffect
hook. Once the form is valid, the button should be enabled and on click of it, it should show an alert saying "Login Successful".
Hint 1: Apart from maintaining local state for
username
andpassword
, you may need to maintain a local state of the form validity. Hint 2: You need to useonInput
event to update value ofusername
andpassword
.
Solve this medium problem to earn 2