就像我在标题中所说的那样,我想在我的脚本中添加多个函数 .rules() 。当我尝试这个时:
$("#braintree-payment-form").validate({});
$("#month").rules('add', {
required: true,
regex: "(0[123456789]|10|11|12)",
messages : {
required: "Expiration date is required.",
regex: "Invalid expiration date."
}
});
$("#year").rules('add', {
required: true,
regex: "([0-9][0-9])",
messages : {
required: "Expiration date is required.",
regex: "Invalid expiration date."
}
});
$("#cardNum").rules('add', {
required: true,
regex: "(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})",
messages : {
required: "Credit card number is required.",
regex: "Invalid credit card number"
}
});
仅应用了最后一个 .rules() ,并且它也应用于第一个输入元素而不是对应的 id 一个。
提前致谢 :)
这是我目前使用的表格:
<form action="#" method="POST" id="braintree-payment-form">
<p>
<label>Card Number</label>
<input type="text" size="20" autocomplete="off" name='number' id='number' data-encrypted-name="number"/>
</p>
<p>
<label>CVV</label>
<input type="text" size="4" autocomplete="off" name='cvv' data-encrypted-name="cvv" id='cvv'/>
</p>
<p>
<label>Expiration (MM/YYYY)</label>
<input type="text" size="2" data-encrypted-name="month" id="month" name = 'month' /> / <input type="text" size="4" data-encrypted-name="year" id="year" name='year' />
</p>
<input type="submit" id="submit" name='braintree'/>
</form>