HTML5 new client-side checksum

Source: Internet
Author: User

1. The checkvalidity () method provided by the form control is verified.

For example, if the Checkvalidity () method returns True
Indicates that all form controls within the form are valid.

<Body>    <formAction="">Birthday:<inputID= "Birth"name= "Birth"type= "Date"><BR>e-mail address:<inputtype= "Email"ID= "Email"name= "Email"><BR>        <inputtype= "Submit"value= "Submit"onclick= "return check ()"></form><Script>    varCheck= function () {        returnCommoncheck ('Birth', 'Birthday', 'The field must be a valid date')            &&Commoncheck ('Email', 'Email', 'fields must be formatted with e-mail')    }    varCommoncheck= function(Fieid, Fiename, tip) {varTargetele=document.getElementById (Fieid); if(TargetEle.value.trim ()== "') {alert (Fiename+ 'fields must be filled in'); return false        }        Else if (!targetele.checkvalidity ()) {Alert (Fiename+tip); return false        }        return true    }</Script></Body>

2. Custom validation application h5 new Setcustomvalidity () method implementation. This method can be called only if the form does not pass a checksum.

For example:

<Body>    <formAction="">Book name:<inputID= "Name"name= "Name"type= "text"Required><BR>Book ISBN:<inputtype= "text"ID= "ISBN"name= "ISBN"Required Pattern= "\d{3}-\d-\d{3}-\d{5}"        ><BR>Book Price:<inputtype= "Number"ID= "Price"name= "Price"Required min= " the"Max= "Max"Step= "5"        ><BR>        <inputtype= "Submit"value= "Submit"onclick= "Check ()"></form><Script>    varCheck= function () {      if(!document.getElementById ('name'). Checkvalidity ()) {document.getElementById ('name'). Setcustomvalidity ('the name of the book is a must'); }            if(!document.getElementById ('ISBN'). Checkvalidity ()) {document.getElementById ('ISBN'). Setcustomvalidity ('Book ISBN is a must'+'\ n and must conform to XXX-X-XXX-XXXXX format (where x represents a number)'); }            if(!document.getElementById (' Price'). Checkvalidity ()) {document.getElementById (' Price'). Setcustomvalidity ('Price is a must.'+'\ n and must be between 20-150 and a multiple of 5.'); }    }    </Script>

HTML5 new client-side checksum

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.