我有一张信用卡处理表格,其中有 2 个选择字段作为到期日期。像这样
<select name="qbms_cc_expires_month" id="qbms_cc_expires_month"><option value="01">01</option><option value="02">02</option><option value="03">03</option><option value="04">04</option><option value="05">05</option><option value="06">06</option><option value="07">07</option><option value="08">08</option><option value="09">09</option><option value="10">10</option><option value="11">11</option><option value="12">12</option></select><span class="required">*</span> <select name="qbms_cc_expires_year" id="qbms_cc_expires_year"><option value="12">2012</option><option value="13">2013</option><option value="14">2014</option><option value="15">2015</option><option value="16">2016</option><option value="17">2017</option><option value="18">2018</option><option value="19">2019</option><option value="20">2020</option><option value="21">2021</option></select>
我已经添加了这个 $.validator.addMethod
$.validator.addMethod(
"ccexpdate",
function (value, element) {
// Initialize todays date i.e start date
var today = new Date();
var startDate = new Date(today.getFullYear(),today.getMonth(),1,0,0,0,0);
// Initialize End/Expiry date i.e. adding 10 years to expire
var futureLimitDate= new Date(today.getFullYear()+10,today.getMonth(),1,0,0,0,0);
var expDate = value;
var expYearCheck='';
// Check Date format
var separatorIndex = expDate.indexOf('/');
if(separatorIndex==-1)return false; // Return false if no / found
var expDateArr=expDate.split('/');
if(expDateArr.length>2)return false; // Return false if no num/num format found
// Check Month for validity
if(eval(expDateArr[0])<1||eval(expDateArr[0])>12)
{
//If month is not valid i.e not in range 1-12
return false;
}
//Check Year for format YY or YYYY
switch(expDateArr[1].length)
{
case 2:expYearCheck=2000+parseInt(expDateArr[1], 10);break; // If YY format convert it to 20YY to it
case 4:expYearCheck=expDateArr[1];break; // If YYYY format assign it to check Year Var
default:return false;break;
}
// Calculated new exp Date for ja
expDate=new Date(eval(expYearCheck),(eval(expDateArr[0])-1),1,0,0,0,0);
if(Date.parse(startDate) <= Date.parse(expDate))
{
if(Date.parse(expDate) <= Date.parse(futureLimitDate))
{
// Date validated
return true;
}else
{
// Date exceeds future date
return false;
}
}else
{
// Date is earlier than todays date
return false;
}
},
"<br />Must be a valid Expiration Date."
);
我如何在我的规则中调用它:{ } 部分?我试过这个 qbms_cc_expires_year: { ccexpdate: { month: '#qbms_cc_expires_month', year: '#qbms_cc_expires_year' } },但它不起作用。