The Setcustomvalidity () method in the JavaScript validation API

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.