Today I Learned

hashrocket A Hashrocket project

Check if a form is valid

You can check if a form passes HTML validations with javascript using the checkValidity function:


 
   Email
   
 

 
   Password
   
 

 
   
   
    validate
   
 



  const button = document.querySelector("#validate")
  if (button) {
    button.addEventListener("click", function() {
      alert(document.forms.login.checkValidity() ? "Form is valid" : "INVALID");
    });
  }
See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.