接着导入jQuery Validation核心js/js/jqueryValidation/jquery.validate.min.js">导入中文提示信息js/js/jqueryValidation/m"/> 接着导入jQuery Validation核心js/js/jqueryValidation/jquery.validate.min.js">导入中文提示信息js/js/jqueryValidation/m">

首页  >  文章  >  web前端  >  jQuery Validation使用教程

jQuery Validation使用教程

jacklove
jacklove原创
2018-06-15 16:08:461805浏览

1、导入js库

jQuery Validation是基于jQuery为核心的,所以必须先导入jQuery核心js文件

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

接着导入jQuery Validation核心js

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

导入中文提示信息js

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

2、默认校验规则

3、默认提示


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

由于已经导入了中文信息提示包,所以默认提示信息为:

$.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} 的数值" )
} );

4、使用方式

①将校验规则写到控件中

本文讲解了jQuery Validation使用教程 ,更多相关内容请关注php中文网。

相关推荐:

gulp模块的方法

js将html生成为图片,并保存在本地

js中函数的三种定义方式

以上是jQuery Validation使用教程的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn