0 votes
in JavaScript by
What are the DOM methods available for constraint validation?

1 Answer

0 votes
by

The below DOM methods are available for constraint validation on an invalid input,

  1. checkValidity(): It returns true if an input element contains valid data.
  2. setCustomValidity(): It is used to set the validationMessage property of an input element. Let's take an user login form with DOM validations
function myFunction() {
  var userName = document.getElementById("uname");
  if (!userName.checkValidity()) {
    document.getElementById("message").innerHTML =
      userName.validationMessage;
  } else {
    document.getElementById("message").innerHTML =
      "Entered a valid username";
  }
}

Related questions

0 votes
asked Oct 13, 2023 in JavaScript by GeorgeBell
0 votes
asked Mar 15 in JavaScript by DavidAnderson
...