接著導入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:461813瀏覽

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