mjacobs2929
asked on
Check card expiry date not less than current Month/Year
How can I validate an expiry date to ensure it is not less than the current Year/month?
I thought the following would work, but 'var thism' of less than 10 seems to lose the leading 0. What is a good way around this?
Many thanks,
MJ
// Check card expiry date not less than current Month/Year
var datenow = new Date();
var thism = datenow.getMonth()+1;
var thisy = datenow.getFullYear();
var currentMonthYear = thisy + "" + thism;
alert(currentMonthYear);
var uExpMonthYear = uExpYear + "" + uExpMonth;
alert(uExpMonthYear);
if ( uExpMonthYear < currentMonthYear ){
submitForm = 0;
alert(AP0021); //AP0021
thisForm.expiry_month.focu s();
return false;
break;
}
I thought the following would work, but 'var thism' of less than 10 seems to lose the leading 0. What is a good way around this?
Many thanks,
MJ
// Check card expiry date not less than current Month/Year
var datenow = new Date();
var thism = datenow.getMonth()+1;
var thisy = datenow.getFullYear();
var currentMonthYear = thisy + "" + thism;
alert(currentMonthYear);
var uExpMonthYear = uExpYear + "" + uExpMonth;
alert(uExpMonthYear);
if ( uExpMonthYear < currentMonthYear ){
submitForm = 0;
alert(AP0021); //AP0021
thisForm.expiry_month.focu
return false;
break;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
one suggestion, I gotta tell ya that is not a good idea to get the current date in JS, since it gets it from the client PC, so the user can change it, and you can't control it, then the validation is useless.
check this code out
http://javascript.internet.com/forms/val-credit-card.html
http://javascript.internet.com/forms/val-credit-card.html