0

I'm using a .net custom validator to check an input date in a form. I want to validation to check the number of days in Feb ie 28/02/2015 but not 29/02/2015.

For the c# server validation this is working fine:

try
{
    DateTime dt = DateTime.Parse("29/02/2015");
}
catch
{
    args.IsValid = false;
}

This will validate as false;

But I can't get a javascript date parse to work in the same way for my client validation. Is there a simple way of achieving this in Javascript?

Bobney
  • 320
  • 3
  • 19

1 Answers1

2

I edited my answer try this one to check days. This will give you some idea on how to do this.

function daysInMonth(month,year) {
   return new Date(year, month, 0).getDate();
}

//July
daysInMonth(7,2009); //31
//February
daysInMonth(2,2009); //28
daysInMonth(2,2008); //29
Nithin Paul
  • 2,169
  • 3
  • 33
  • 55
  • Thanks, got me on the right track found [Guffa's answer](http://stackoverflow.com/questions/8098202/javascript-detecting-valid-dates) worked for me. – Bobney Mar 02 '15 at 10:56