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