Link to home
Start Free TrialLog in
Avatar of cbrune
cbrune

asked on

javascript regex for valid month and day not year

javascript regex for valid month and day not year
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

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
if you have more complex date functionality needs, you may also want to check out DateJS, a jquery date validation plug-in.

https://code.google.com/p/datejs/wiki/APIDocumentation
Here is an even simpler test assuming current year.

FIDDLE

function testDate(dd,mm,yyyy) {
  yyyy = yyyy||new Date().getFullYear(); // optional year
  mm = mm-1; // JS Months are 0 based
  var testDate = new Date(yyyy,mm,dd,12,0,0,0);
    window.console&&console.log(testDate); // remove when happy
  return dd == testDate.getDate() && mm == testDate.getMonth() && testDate.getFullYear() == yyyy;
}

var dd = 29; // your date
var mm = 2; // your month
window.console&&console.log(testDate(dd,mm));

dd = 32; // your date
mm = 13; // your month
window.console&&console.log(testDate(dd,mm));

dd = 2; // your date
mm = 3; // your month
window.console&&console.log(testDate(dd,mm));

Open in new window

Avatar of cbrune
cbrune

ASKER

I've requested that this question be deleted for the following reason:

2
i don't think "2" is a sufficient reason on wanting to delete the question....
Avatar of cbrune

ASKER

good answer