Regex to validate date format dd/mm/yyyy

后端 未结 21 2520
挽巷
挽巷 2020-11-21 06:32

I need to validate a date string for the format dd/mm/yyyy with a regular expresssion.

This regex validates dd/mm/yyyy, but not the invalid

21条回答
  •  日久生厌
    2020-11-21 07:05

    Notice:

    Your regexp does not work for years that "are multiples of 4 and 100, but not of 400". Years that pass that test are not leap years. For example: 1900, 2100, 2200, 2300, 2500, etc. In other words, it puts all years with the format \d\d00 in the same class of leap years, which is incorrect. – MuchToLearn

    So it works properly only for [1901 - 2099] (Whew)

提交回复
热议问题