Hi, I have a code in jquery validate rules validator.addMethod that allows me to enter a check for a future date on the card expiration date, i.e. 10/2015, indeed, I would like to ask if there is a way to add a limit of up to 20 years in the future, as they can currently enter the expiration date of the card 10/2099 or more. Thanks in advance!
Here is the code that I have, it also needs a special message. Exceeds date range
<input type="text" name="field_4" id="field_4" value="">
$.validator.addMethod(
"Future",
function (value, element) {
var today = new Date();
var startDate = new Date(today.getFullYear(),today.getMonth(),1,0,0,0,0);
var expDate = value;
var separatorIndex = expDate.indexOf('/');
expDate = expDate.substr( 0, separatorIndex ) + '/1' + expDate.substr( separatorIndex );
return Date.parse(startDate) <= Date.parse(expDate);
},
"Must be a valid Expiry Date"
);
$(function() {
$( "#Form" ).validate({
rules: {
field_4: {
required: true,
Future: true,
minlength: 7
},
source
share