0
function isMMDD(value) {
    var re = /^([0]?[1-9]|1[0-2])\/([0-2]?[0-9]|3[0-1])$/;
    if (re.test(value)) {
        return true;
    }
    else
        return false;
}

I would like to have 02/30 as invalid too.

  • 1
    Possible duplicate of [Regular Expression to match valid dates](https://stackoverflow.com/questions/51224/regular-expression-to-match-valid-dates) – Rodrigo García Sep 18 '17 at 01:45
  • See [this](https://stackoverflow.com/a/8768241/5894241) answer in particular. It handles the part about validating dates such as 02/30. – Nisarg Shah Sep 18 '17 at 07:56

1 Answers1

0

With information in here

If you are validating the user's input of a date in a script, it is probably easier to do certain checks outside of the regex. For example, excluding February 29th when the year is not a leap year is far easier to do in a scripting language. It is far easier to check if a year is divisible by 4 (and not divisible by 100 unless divisible by 400) using simple arithmetic than using regular expressions.

In your case it applies the same thing, also it is a very asked question.

here, here and also (but not exactly) here

Rodrigo García
  • 1,357
  • 15
  • 26
  • Hi @Rodrirokr thanks a lot for your explanation. I'm not that skilled to apply what you said above. Would you make it more clear and show me the code? Thanks in advance! – Abdullah Al Shammari Sep 18 '17 at 04:10