0

i need to validate the date format for a particular date picker control. If I enter "99/99/9999" which is similar to the format DD/MM/YYYY manually, it does not throw up a validation error.

Is there any way to achieve this?

Poppy
  • 2,902
  • 14
  • 51
  • 75

1 Answers1

1

You can validate a date with this function. Just pass in your input's value. Extracted from this little validation plugin I'm working on.

var isValidDate = function (value) {
    var match = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.exec(value),
    isDate = function (m, d, y) {
        return m > 0 && m < 13 && y > 0 && y < 32768 && d > 0 && d <= (new Date(y, m, 0)).getDate();
    };
    return match && isDate(match[1], match[2], match[3]);
}
elclanrs
  • 92,861
  • 21
  • 134
  • 171