可以在這裏找到:http://docs.jquery.com/Plugins/Validation/rules#.22add.22rulesjQuery驗證:使用jQuery的驗證林抽象規則
目前,我有一些設置,像這樣我的「自定義」規則:
else if(valID =="#shipForm")
{
$("#fName").rules("add",{regexName: "^[a-zA-Z]+(([\'\-][a-zA-Z])?[a-zA-Z]*)*$",minlength: 2,messages:{minlength:"Must be 2 characters."}});
$("#lName").rules("add",{regexName: "^[a-zA-Z]+(([\'\-][a-zA-Z])?[a-zA-Z]*)*$",minlength: 2,messages:{minlength:"Must be 2 characters."}});
$("#sAdd1").rules("add",{stringCheck: "",minlength:2,messages:{minlength:"Enter your complete street address."}});
$("#sAdd2").rules("add",{stringCheck: ""});
$("#city").rules("add",{stringCheck: "",minlength:2,messages:{minlength:"Enter the full name of your city"}});
$("#zipcode").rules("add",{stripZip: ""});
$("#phoneIn").rules("add",{stripPhone: "",maxlength:15,messages:{maxlength:"Phone number exceeds allowed length"}});
$("#altPhone").rules("add",{stripPhone: ""});
$("#state").rules("add",{checkMenu: ""});
$("#country").rules("add",{checkMenu: ""});
}
我希望能做..正在抽象出.rules並能夠從一個函數中抓取它們。我的問題是,他們不只是字符串,所以即時通訊缺乏一個想法,我怎麼能從另一個函數帶來的信息和填充.rules(「規則的傳遞價值」)
這並不工作,但這是一個例子東西我有點希望
function getRule(rule)
{
switch (rule)
{
case "fName":
return "\"add\",{regexName: \"^[a-zA-Z]+(([\'\-][a-zA-Z])?[a-zA-Z]*)*$\",minlength: 2,messages:{minlength:\"Must be 2 characters.\"}}";
break;
}
}
但我顯然不能只傳遞一個字符串,並將其運行回.rules。
任何想法的?
鑑於它的使用方式,也許返回一個數組而不是一個對象?這樣他可以稱之爲'.rules(myruleDef)'不? – Ryley 2010-06-11 16:54:41
謝謝,我認爲這對我目前的設置來說效果最好 – littlevahn 2010-06-11 19:53:28