JQuery validation makes validation so Easy (ii)

Source: Internet
Author: User

The previous example we are a unified reference jquery.validate.js so all required fields are prompted with this field is required.

Now you want to change to a dynamic prompt, such as the name if it is empty, the prompt name cannot be empty, if the password is blank, the prompt password cannot be empty.


This time we officer the rules in the code.

First, the file is introduced first.

<script src= "Js/jquery-1.8.0.min.js" type= "Text/javascript" ></script><script src= "js/ Jquery.validate.js "type=" Text/javascript "></script>

Next, declare the following HTML fragment

<form action= "" id= "Jvform" > Name: <input type= "text" name= "username" id= "username"/></br> password:< Input type= "password" name= "password" id= "password"/></br><input type= "Submit" value= "Submit"/></form >
compared to the previous class= "required" .


The final check rule is as follows:

$ (function () {    $ ("#jvForm"). Validate ({        rules: {            username: {                required:true            },            password: {                Required:true            }        },        messages: {            username: {                required: "Name cannot be empty!"            },            password: {                Required: "Password cannot be empty!"}}    );})

Run effect



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.