Jquery. Validate Chinese API and application example (1) simple verification

Source: Internet
Author: User

Jquery. Validate API: jquery_validateapi .rar

For details about how to use simple verification rules, go to jquery. Validate Chinese API and application instance (2) simple verification-rule application

The following is a simple application example:

1. Verification with class style, simple usage, but not custom error information, can only modify built-in messages in the jquery-1.4.1.min.js, does not support advanced validation rules.

    <script type="text/javascript" language="javascript" src="http://www.cnblogs.com/Scripts/jquery-1.4.1.min.js"></script>    <script type="text/javascript" language="javascript" src="http://www.cnblogs.com/Scripts/jquery.validate.min.js"></script>        <table border="0" cellpadding="0" cellspacing="0">        <tr>            <td>      <input type="text" id="UserEmail" class="required email" />
</td> </tr> <tr> <td>      <input type="password" id="Password" class="required" />
</td> </tr> <tr> <td> <input type="submit" value="submit" onclick="checkInput();" /> </td> </tr> </table> </form> <script language="javascript" type="text/javascript"> function checkInput() { if ($("#loginForm").valid()) { return true; } return false; } </script>

Of course, if you do not want to use the onclick event for submission verification, you can also add jquery monitoring during page loading. The Code is as follows:

       $(document).ready(function () {            jQuery("#loginForm").validate();        });   

In this case, you do not need to add onclick = "checkinput ();" to the submit button.

2. JSON string verification. If this rule is used for verification, the jquery. Metadata. Pack. js file must be introduced.

Modify the preceding two inputs as follows:

<Input type = "text" id = "useremail" class = "{validate: {required: True, email: true}"/>
<Input type = "password" id = "password" class = "{validate: {required: True, minlength: 6, messages: {required: 'Enter the password', minlength: 'password must be at least six characters' }}"/>

We can see that we can customize the error message.

In addition, you must add the following code to the page:

$ (Document). Ready (function (){
$ ("# Loginform"). Validate ({
Meta: "Validate"
});
});

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.