jquery Plugin validate implement custom form validation _jquery

Source: Internet
Author: User
Tags curl jquery form validation

This article illustrates the jquery Validate form verification plug-in, how to customize a validation method, share for everyone to refer to, the specific content as follows

The effect is as follows:

Validation failure Effect:

To verify successful results:

Specific steps:

1, the introduction of the dependency package

 <script src= ". /.. /scripts/jquery-1.3.1.js "type=" Text/javascript "></script>
 <script src=" Lib/jquery.validate.js " Type= "Text/javascript" ></script>

2, add error style and success style

 em {font-weight:bold; padding-right:1em; vertical-align:top;}
Em.error {
 Background:url ("images/unchecked.gif") no-repeat 0px 0px;
 padding-left:16px;
}
em.success {
 Background:url ("images/checked.gif") no-repeat 0px 0px;
 padding-left:16px;
}

3. Customize a validation method

 Customize a validation method
 $.validator.addmethod (
 "formula",//validation method name
 function (value, element, param) {//validation rules
 return value = = eval (param);
 }, 
 ' Please enter the result of the math formula calculation correctly '///Verify the hint information
 );

4. Call Style display

 Errorelement: "em",  //used to create error message label
 success:function (label) {  //Verify successful execution of callback function
  // The label points to the above error message label em
  label.text ("")  //Empty error prompt messages
  . addclass ("Success"); Add a custom success class
 }

5, detailed code as follows

  

This article has been organized into the "jquery form verification Encyclopedia," Welcome to learn to read.

The above is the entire content of this article, I hope to learn form verification to help you.

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.