Validate control HTML5 before excute method


Validate control HTML5 before excute method 

* HTML

<form id="form" action="">

  <input type="text" required />
  <input id="submit-hidden" type="submit" style="display: none" />

</form>

<button id="btn-submit">Submit</button>

*Javascript

$("#btn-submit").on("click", function() {
  if (!$("#form")[0].checkValidity()) {
    // If the form is invalid, submit it. The form won't actually submit;
    // this will just cause the browser to display the native HTML5 error messages.
    $("#form").find("#submit-hidden").click();
  }
});