Form Validation

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 and password, you may need to maintain a local state of the form validity. Hint 2: You need to use onInput event to update value of username and password.



Solve the practice problems to earn    DevCoin image 
Coding Area

Copyright © 2022 opendevs

Learn ● Develop ● Ace
All illustrations by Storyset