[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3760
  • Last Modified:

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;
    }
0
mjacobs2929
Asked:
mjacobs2929
  • 2
1 Solution
 
alambresCommented:
var thism = datenow.getMonth()+1;
if (thism<10) thism = "0" + thism;
0
 
alambresCommented:
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.
0
 
archrajanCommented:
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now