[英]Jquery Validation Engine Customizing
我想驗證僅允許字母數字和/
符號的文本字段。 我正在使用jquery驗證引擎來驗證文本字段。
我已經嘗試過class="validate[required,custom[onlyLetterSp]]"
僅允許使用字母。
誰能告訴我如何自定義上述要求?
在包括jQuery和jQuery-validate腳本文件之后添加
jQuery.validator.addMethod("onlyLetterSp", function(value, element, param) {
if (!value) return true;
return /^[a-zA-Z0-9\/]+$/.test(value);
}, 'Alphanumeric or slash Only.');
然后與輸入字段一起使用
class="validate[required, onlyLetterSp]"
您可以使用自定義功能進行驗證,如下所示。
在HTML
class="validate[required,funcCall[check_what_you_need]]"
在jQuery中
function check_what_you_need(field, rules, i, options){
if (conditions you need) {
// this allows the use of i18 for the error msgs
return options.allrules.validate2fields.alertText;
}
}
您將需要向jquery.validationEngine-en.js添加一個類(假設您具有英文版的驗證消息),如下所示:
"onlyLetterSp":
{
"regex": /^[a-zA-Z0-9\/]+$/,
"alertText": "* Alphanumeric characters only"
},
然后在您的html控件中,
class="validate[custom[onlyLetterSp]]"
希望有幫助:)
對於波蘭標志:
{"regex":/^[a-zA-ZąĄęĘżŻźŹćĆńŃłŁóÓ\ \']+$/,"alertText":"* Tylko litery"}
記住要廣告charset =“ utf-8”
<script src="jquery.validationEngine.js" charset="utf-8" type="text/javascript"></script>
如果仍然有問題,請檢查文件編碼( Wikipedia-BOM )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.