Home > Web Front-end > JS Tutorial > body text

jQuery Validation usage tutorial

jacklove
Release: 2018-06-15 16:08:46
Original
1814 people have browsed it

1. Import js library

jQuery Validation is based on jQuery as the core, so you must first import the jQuery core js file

<script src="<%=path%>/js/bootstrap/jquery-3.2.1.min.js"></script>
Copy after login

Then import the jQuery Validation core js

<script src="<%=path%>/js/jqueryValidation/jquery.validate.min.js"></script>
Copy after login

Import Chinese prompt information js

<script src="<%=path%>/js/jqueryValidation/messages_zh.js"></script>
Copy after login

2. Default verification rules

3 , Default prompt


messages: {
    required: "This field is required.",
    remote: "Please fix this field.",
    email: "Please enter a valid email address.",
    url: "Please enter a valid URL.",
    date: "Please enter a valid date.",
    dateISO: "Please enter a valid date ( ISO ).",
    number: "Please enter a valid number.",
    digits: "Please enter only digits.",
    creditcard: "Please enter a valid credit card number.",
    equalTo: "Please enter the same value again.",
    maxlength: $.validator.format( "Please enter no more than {0} characters." ),
    minlength: $.validator.format( "Please enter at least {0} characters." ),
    rangelength: $.validator.format( "Please enter a value between {0} and {1} characters long." ),
    range: $.validator.format( "Please enter a value between {0} and {1}." ),
    max: $.validator.format( "Please enter a value less than or equal to {0}." ),
    min: $.validator.format( "Please enter a value greater than or equal to {0}." )
}
Copy after login

Since the Chinese information prompt package has been imported, the default prompt information is:

$.extend( $.validator.messages, {
    required: "这是必填字段",
    remote: "请修正此字段",
    email: "请输入有效的电子邮件地址",
    url: "请输入有效的网址",
    date: "请输入有效的日期",
    dateISO: "请输入有效的日期 (YYYY-MM-DD)",
    number: "请输入有效的数字",
    digits: "只能输入数字",
    creditcard: "请输入有效的信用卡号码",
    equalTo: "你的输入不相同",
    extension: "请输入有效的后缀",
    maxlength: $.validator.format( "最多可以输入 {0} 个字符" ),
    minlength: $.validator.format( "最少要输入 {0} 个字符" ),
    rangelength: $.validator.format( "请输入长度在 {0} 到 {1} 之间的字符串" ),
    range: $.validator.format( "请输入范围在 {0} 到 {1} 之间的数值" ),
    max: $.validator.format( "请输入不大于 {0} 的数值" ),
    min: $.validator.format( "请输入不小于 {0} 的数值" )
} );
Copy after login

4. Use Method

①Write the validation rules into the control

This article explains the jQuery Validation usage tutorial. For more related content, please pay attention to the php Chinese website.

Related recommendations:

Methods of the gulp module

##js generates html as images and saves them locally

Three ways to define functions in js

The above is the detailed content of jQuery Validation usage tutorial. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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