jQuery-Form-Validator
jQuery-Form-Validator copied to clipboard
CC expiry: link a month and a year dropdown to validate for date in future?
Just a question, not an issue:
This is for credit card expiry dates. Two dropdowns: one for month, one for year. Is there a way to link them and validate for date in the future?
Using slects with ids and bypassing the 'value' returned - I'm sure it can be refined but it works : : : : data-validation='expiry_date'
$.formUtils.addValidator({ name : 'expiry_date', validatorFunction : function(value, $el, config, language, $form) {
var usermo=$('#exp_m').val();
var useryr=$('#exp_y').val();
usermo= (usermo.length == 1)? '0'+usermo : usermo;
user_yrmo=useryr+usermo;
var dt = new Date();
var mo=(dt.getMonth()+1).toString();
mo= (mo.length == 1)? '0'+mo : mo;
var yrmo = dt.getFullYear().toString();
yrmo=yrmo+mo;
if(user_yrmo>=yrmo){
$('#exp_m, #exp_y').css({"border-color": "#fff",
"border-width":"0",
"border-style":"solid"}).removeClass('error');
}else{
$('#exp_m, #exp_y').css({"border-color": "#ee2200",
"border-width":"1px",
"border-style":"solid"}).addClass('error');
}
return(user_yrmo>=yrmo);
}, errorMessage : 'Expiry date is not valid', errorMessageKey: 'expiry_date_invalid' });