It isn't much more trouble to make sure the first number group
is between 01(or 1) and 12.
var datestring= '02/2014';
var rx=/^(0?[1-9]|1[0-2])[\/-](\d\d(\d\d)?)$/g;
alert(rx.test(datestring));
// The parentheses and /g flag can be used to test the expiration date-
Code:
// The parentheses and /g flag can be used to test the expiration date-
var datestring= '10/12';
var rx=/^(0?[1-9]|1[0-2])\D(\d\d(\d\d)?)$/g;
var day= rx.exec(datestring);
if(day){
var today= new Date(),
ty= today.getFullYear(), tm= today.getMonth(),
y= day[2]- 0;
if(y<100) y+= 2000;
alert(y>ty || (y== ty && day[1]-1>= tm))
}
else alert(NaN);