Setcustomvalidity () Method:
Sets the Validationmessage property of the input element, which is used to customize the method of the error message.
Note: When a custom prompt is set with setcustomvalidity, the validity.customerror becomes true, and checkvalidity () always returns false, resulting in the correct format of the re-entry, or Will prompt you to set the error message.
Workaround: Use Obj.validity.patternMismatch to judge, if the input format is correct, will setcustomvalidity empty, so that JavaScript re-judge the value of Validity.customerror.
Reference: http://www.runoob.com/js/js-validation-api.html
In this link, there are three ways to empty the setcustomvalidity, but after testing, only the first method setcustomvalidity("') can be used.
<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "UTF-8"> <title>The Setcustomvalidity () method is not used</title></Head><Body> <formname= "Test"Action=""Method= "POST"> <inputID= "Input"type= "text"Required= "Required"placeholder= "Please enter a 4-11-digit password plus a number"pattern="^(?! [0-9]+$) (?! [a-za-z]+$] [0-9a-za-z]{4,14}$ ]Oninput= "this.setcustomvalidity (')"> <inputtype= "Submit"onclick= "Setmytext ()"> </form> <Scripttype= "Text/javascript"> functionSetmytext () {varobj=document.getElementById ("input"); if(Obj.validity.patternMismatch=== true) {obj.setcustomvalidity ("the password is required."); } Else{obj.setcustomvalidity ("'); } } </Script></Body></HTML>
The Setcustomvalidity () method in the JavaScript validation API