View Single Post
Old 10-03-2012, 08:19 PM   PM User | #4
mrhoo
Regular Coder

 
Join Date: Mar 2006
Posts: 708
Thanks: 30
Thanked 127 Times in 118 Posts
mrhoo will become famous soon enoughmrhoo will become famous soon enough
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);

Last edited by mrhoo; 10-03-2012 at 08:34 PM..
mrhoo is offline   Reply With Quote