Jquery.validate.js "Simple and practical form validation framework"

Source: Internet
Author: User

    • Online Demo 1
    • Local Downloads
Original link: http://www.gbtags.com/gb/share/5749.htm

Recently in the user login, registration, and User Center ... Then in the MU class network jquery.validate need place, according to their own needs to make the details of the changes, it is important to style it.

The first time to publish these, not good to say don't mind, start. First of all:

    1. $("#form"). Validate({
    2. //Edit in this area
    3. });

Validation often requires debugging, and the framework includes a method, as follows:

    1. Debug:True, //debug mode (not committed)

To an instance, HTML:

  1. <div Class="Form-group">
  2. <label for ="username"> user name:</label>
  3. <input type="text" name="username" id="username" placeholder="Please enter user name" />
  4. </div>

Set validation with the Rules method, then the requirement is: required, length between 3-10:

  1. $(document). Ready(function() {
  2. $("#form"). Validate({
  3. Debug:True, //debug mode
  4. Rules: {
  5. Username: {
  6. Required:true, //enable required fields
  7. Rangelength: [3,] //Please enter a value between 3 and 10 bits
  8. };
  9. };
  10. });
  11. });

My understanding is that you get the name value and type types to validate. Let's re-enter the password:

Html:

  1. <div Class="Form-group">
  2. <label for ="Confirm-password"> Confirm password:</label>
  3. <input type="password" name= "Confirm-password" id=" Confirm-password " placeholder=" Please enter your password again " />
  4. </div>
  5. Js:
    1. Password: {
    2. Required:true,
    3. Rangelength: [6,]
    4. },
    5. "Confirm-password": {
    6. Equalto:"#password" //must have the same password
    7. }

If you want to customize the prompt message, then use the messages method:

    1. Messages: {
    2. Username: {
    3. Required:"user name cannot be left blank", //user name must fill in the prompt
    4. Rangelength:"Please check if the length of the number you entered is between 2 and 10" //user name length hint
    5. }

Let's talk about style, when the input box is wrong, class becomes error, and when the input box is correct, class class becomes valid, so different color border is added:

  1. . form-group input. Error{
  2. Border-color: #E74C3C;
  3. }
  4. . form-group input. Valid {
  5. Border-color: #55D98D;
  6. }

The message of the prompt? When the input box prompts an error, the note pops up, the class name is error, the input box prompt is correct, the note is hidden, and the class name success is added, then:

    1. . form-group span. Error{
    2. Color: #E74C3C;
    3. }
    4. . form-group span. Success{
    5. Display: none;
    6. }

In fact, there are many ways, such as: Groups, errorplacement ... Basically can meet the requirements of form verification, demo there is a demo, see it.

Original link: http://www.gbtags.com/gb/share/5749.htm

Jquery.validate.js "Simple and practical form validation framework"

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.