jquery Verification Plug-in Validation usage guide

Source: Internet
Author: User
Tags dateformat

Jquery.validation.js in the front-end verification is very convenient to use, the functionality provided basically to meet most of the verification requirements, the following we will carefully study the use of the jquery plug-in specific methods.

In the process of web development, sometimes we need to verify that the information entered by the user meets our requirements, so we will validate the data submitted by the user. The verification is performed two times, one at the client and one at the server. Client-side validation can enhance the user experience.

jquery verification Plug-ins are many, the implementation of the same functionality. This article is just a jquery.validate in the jquery verification plug-in

Jquery. Validation is an excellent jquery plug-in that validates client forms and provides a number of customizable properties and methods for good scalability.

1.jquery.validate Plug-in Features

Simple implementation of client information validation, filtering the information that does not meet the requirements

2.jquery.validate official Address

Official address: http://jqueryvalidation.org/, there are detailed instructions for the use of Plug-ins

Official demo:http://jquery.bassistance.de/validate/demo/

How to use 3.jquery.validate

1. Reference JS

?

1 2 <script type= "Text/javascript" src= "jquery.js" ></script> <script type= "Text/javascript" Jquery.validate.js "></script>

2.css style, customizable, simple to add an error style, or use the style in the official demo.

?

1 2 3 4 . error{color:red; margin-left:8px;}

3.js Code

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 The "border:0;padding:0" of the

The above code uses only the properties and methods provided by the plug-in. You can also customize the validation method. Such as

?

1 2 3 4 5 6 7 $.validator.addmethod ("Checkusername", function (value) {//value for validated value, corresponding to element ID//method code}, ' username format is incorrect ');

Using a custom method is also very simple, just need the element ID: "Checkusername"

4. Use of HTML

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67-68 &lt;form id= "Signupform" autocomplete= "Off" method= "get" action= "" &gt; &lt;table&gt; &lt;tr&gt; &lt;td class= "label" &gt;&lt;label id= "Lfirstname" for= "FirstName" &gt; Name &lt;/label&gt;&lt;/td&gt; &lt;td class= "field" &gt;&lt;input id= " FirstName "Name=" FirstName "type=" text "value=" "maxlength=",/&gt;&lt;/td&gt; &lt;td "status" class= &gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class= "label" &gt;&lt;label id= "Lusername" for= "username" &gt; User name &lt;/label&gt;&lt; /TD&gt; &lt;td class= "field" &gt;&lt;input id= "username" name= "username" "type=" text "value=" "maxlength=" "/&gt;&lt;/" Td&gt; &lt;td class= "status" &gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class= "label" &gt;&lt;label id= "Lpassword" for= "password" &gt; Password &lt;/label&gt;&lt;/td&gt; &lt;td class= "field" &gt;&lt;input id= "password" name= "password" type= "Password" maxlength= "value=" "/&gt;&lt;/td&gt; &lt;td class=" status "&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &LT;TD class= "label" &gt;&lt;label id= "lpassword_confirm" for= "Password_confir"M "&gt; Confirm password &lt;/label&gt;&lt;/td&gt; &lt;td class=" field "&gt;&lt;input id=" password_confirm "Name=" password_confirm "type=" password "maxlength=" "value=" "/&gt;&lt;/td&gt; &lt;td class=" status "&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &LT;TD class= "label" &gt;&lt;label id= "Lemail" for= "email" &gt; Mailbox &lt;/label&gt;&lt;/td&gt; &lt;td class= "field" &gt; &lt;input id= "Email" name= "email" type= "text" value= "" maxlength= "", "/&gt;&lt;/td&gt; &lt;td class=" status "&gt;&lt;/ td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class= "label" &gt;&lt;label&gt; sex &lt;/label&gt;&lt;/td&gt; &lt;td class= "field" Colspan= "2" style= "vertical-align:top; padding-top:2px; " &gt; &lt;table&gt; &lt;tbody&gt; &nbsp; &lt;tr&gt; &lt;td style= "padding-right:5px;" &gt; &lt;input id= "sex_men" name= "DateFormat" type= "Radio" value= "0"/&gt; &lt;label id= "lbl_sex_men" for= "Dateformat_" EU "&gt; Men &lt;/label&gt; &lt;/td&gt; &lt;td style=" padding-left:5px; &gt; &lt;input id= "sex_women" name= "DateFormat" type= "Radio" value= "1"/&gt; &lt;label id= "Lbl_sex_women "for=" dateformat_am "&gt; Women &lt;/label&gt; &lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &nbsp; &lt;tr&gt; &lt;td class= "label" &gt; &lt;/td&gt; &lt;td class= "field" colspan= "2" &gt; &lt;div id= "termswrap" &gt; &lt;input id= "terms" type= "checkbox" name= "terms"/&gt; "&lt;label id=" lterms "for=" Terms &gt; to read and agree to the terms of the website .&lt;/label&gt; &lt;/div&gt; &lt;!--/termswrap--&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &LT;TD class= "label" &gt;&lt;/td&gt; &lt;td class= "field" colspan= "2" &gt; &lt;input id= "signupsubmit" name= "signup" Type= "Submit" value= "register"/&gt; &lt;/td&gt; &lt;/tr&gt; &nbsp; &lt;/table&gt; &lt;/form&gt;

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.