JqueryValidate
The JQuery Validate plugin provides a powerful validation feature for forms, making it easier to validate client forms, while providing a number of customization options to meet the needs of your application.
1. First, if we do not have jquery.validata.js, then we need to download it. Click on the god-given download link
2. Create the runtime environment, that is, to introduce the plugins we need.
<script src= "Jquery-1.9.1.js" type= "Text/javascript" charset= "Utf-8" ></script>
<script src= "Jquery.validate.min.js" type= "Text/javascript" charset= "Utf-8" ></script>
3. Write HTML content and create a form form
<form id="Demoform"> <p> <label for="User">username:</label> <input type="text"Name="username"Id="User"/> </p> <p> <label for="Pass">password:</label> <input type="Password"Name="Password"Id="Pass"/> </p> <p> <label for=" Age"> age:</label > <input type="text"Name=" Age"Id=" Age"/> </p> <p> <label for="Post">postcode:</label> <input type="text"Name="Postcode"Id="Post"/> </p> <input type="Submit"Value="Submit"Id="btn"/> </form>
The effect is as follows:
4. Edit the JS code
<script type="Text/javascript">$ (function () {//Form form to bind the desired action$('#demoForm'). Validate ({rules:{//return element Validation rule//the name value of the binding elementusername:{Required:true,//set to Required optionrangelength:[3,6]//minimum length and maximum length}, password:{//the name value of the binding elementRequiredtrue,//set to Required optionrangelength:[6, A]//minimum length and maximum length}, age:{//the name value of the binding element//min:18,//Minimum Value//max:999,//Maximum Valuerange:[ -,999],//minimum value and maximum valuerangelength:[1,3],//minimum length and maximum lengthDigitstrue //positive integers}, postcode:{//the name value of the binding elementRequiredtrue,//set to Required optionPostcode:true //Custom Validation } }, //tips for validating errorsmessages:{username:{//the name value of the binding elementRequired'This entry is required',//error message for promptRangelength:'user name is 3-6 bits long' //error message for prompt}, password:{//the name value of the binding elementRequired'This entry is required',//error message for promptRangelength:'user name is 6-12 bits long' //error message for prompt}, age:{//the name value of the binding elementRange'The age must be between 18--999',//error message for promptRangelength:'Number of positions',//error message for promptDigits'age must be a positive integer' //error message for prompt}, postcode:{//the name value of the binding elementRequired'This entry is required' //error message for prompt } }, //actions that are performed when the form is validated bysubmithandler:function () {alert ("Verify all through") }, //actions to take when a form that is not validated is submittedinvalidhandler:function () {alert ("No"); } }); //Customizing a form validation$.validator.addmethod ('Postcode', function (value) {varreg=/^[0-9]{6}$/; returnreg.test (value); },'must be in zip format') }) </script>
As follows:
Well, that's the step of using jquery validate. There are also some simple validation properties in the code.
If you need a closer look, poke me! Poke me!
JQuery Validate Plugin