Jquery plugin Validation

Source: Internet
Author: User
The validation plug-in is used for basic verification.


The three references from top to bottom are jquery ontology references, jquery-validation references, and jquery-validation error prompts references. Just like the autocomplete plug-in. After the validation plug-in is introduced into the project, we will find an extra one.
The validate method.
Syntax
$ (
'Form'
). Validate ({
Rules :{}, errorshow: function (error, element ){}})

Parameter? Description
Rules Returns the validation rules for the element. The specific rules and rule definitions are shown below.
Errorshow If the verification fails, the prompt statement is returned. Errorshow can be modified
Error Error message returned when verification fails
Element Verified Element
Note: The validate method can only verify the form element. However, we need to verify the input element, so we can only send the element to be verified to the form. Then we are talking about how to write the rules verification rules. Note: The username mail and others written below are all the name attributes of the input element. Element name: {verification rule, verification rule ...}
  1. Rules :{
  2. Username: {required: True, Minlength: 7 },
  3. mail: {required: true , email: true },
  4. password: {required: true , minlength: 6, maxlength: 6 },
  5. enterpassword: {required: true , failed to: Password },
  6. homepage: {required: true , URL: true },
  7. birthday: {required: true , Date: true },
  8. Xueya: {digits: True}
  9. },

For more verification rules, you can view the error information in the. js file.Note: to verify whether B is the same as a, you need to set the ID attribute for.

Personal write instance

<Head> <title> </title> <SCRIPT src = "jquery1.7.js" type = "text/JavaScript"> </SCRIPT> <SCRIPT src = "jquery-validation-1.9.0/jquery. validate. JS "type =" text/JavaScript "> </SCRIPT> <SCRIPT src =" jquery-validation-1.9.0/localization/messages_cn.js "type =" text/JavaScript "> </SCRIPT> <SCRIPT type = "text/JavaScript"> $ (document ). ready (function () {$ ('# form1 '). validate ({rules: {Username: {required: True, minlength: 7}, mail: {required: True, email: true}, password: {required: True, minlength: 6, maxlength: 6}, enterpassword: {required: True, failed to: Password}, homepage: {required: True, URL: true}, birthday: {required: True, Date: true}, xueya: {digits: true}, errorshow: function (error, element) {error. appendto (element. siblings ('span '))}})}) </SCRIPT> 

 

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.