Link to home
Start Free TrialLog in
Avatar of mjacobs2929
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.focus();
      return false;
      break;
    }
ASKER CERTIFIED SOLUTION
Avatar of alambres
alambres

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alambres
alambres

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.