Home > Web Front-end > JS Tutorial > jQuery Validation Plugin verification plug-in manual verification_jquery

jQuery Validation Plugin verification plug-in manual verification_jquery

WBOY
Release: 2016-05-16 15:18:02
Original
1187 people have browsed it

jquery.validate is a verification framework under jquery. With the advantages of jquery, we can quickly verify some common inputs, expand our own verification methods, and also have good support for internationalization.

The normal verification mode is as follows:

<form id="ff" action="xxx"> 
... 
<input type="submit" value="提交"> 
</form> 
[java] view plaincopy在CODE上查看代码片派生到我的代码片
$('#ff').validate() 
Copy after login

As long as you click the submit button, the plug-in will automatically verify.

But sometimes we want to click other buttons to validate the form, and then do the rest based on the validation results of the form.

Looking at the source code, I found that there is a form() method. This method is to perform verification operations, although the literal meaning of the method does not match.

Then we can do this:

var validator;// 申明一个全局变量 
$(function(){ 
validator = $('#ff').validate();// 这句话会返回一个对象 
}) 
function add() { 
var b = validator.form();// 返回一个布尔值 
if(b){ // 验证成功 
// do add... 
} 
} 
<button onclick="add()">保存</button> 
Copy after login

If a verification error occurs, an error message will be displayed. If you want to clear the error message, you can call the validator.resetForm(); method

In this way, with the two methods validator.form() and validator.resetForm() we can use the verification plug-in flexibly.

Validation fields

required – required field

remote – remote verification

minlength – Minimum length verification

maxlength – maximum length verification

rangelength – length range validation

min – minimum value verification

max – maximum value verification

range – range value validation

email – Email address verification

url – URL address verification

date – date verification

dateISO –ISO date format verification

number – Decimal number validation

digits – digital verification

creditcard – credit card number verification

equalTo – Verify that the value of another text box is equal

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template