Regex to validate dates in this format d/m/yyyy

后端 未结 3 2088
隐瞒了意图╮
隐瞒了意图╮ 2020-12-20 03:03

I found a regex that works wonders,but it forces leading 0\'s on month and day and I need to accept dates that have the month and/or day in a single digit format

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-20 04:02

    ^(((0?[1-9]|[12]\d|3[01])\/(0?[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0?[1-9]|[12]\d|30)\/(0?[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0?[1-9]|1\d|2[0-8])\/0?2\/((1[6-9]|[2-9]\d)\d{2}))|(29\/0?2\/((1[6-9]|[2-9]\d)(0?[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$

    Same as your provided regexp with optional leading 0s.

提交回复
热议问题