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"
});
});