Correct Regular expressions to match a date

后端 未结 11 805
不知归路
不知归路 2021-01-27 09:50

What is the correct regular expression to use to validate a date like. 2009-10-22 or 2009-01-01 etc. Platform PHP

11条回答
  •  没有蜡笔的小新
    2021-01-27 10:34

    As you have to deal with accepting 2009-02-28 but not 2009-02-29 but accept 2008-02-28 you need more logic that 1 think a regex can give. (But if someone can show it I would be impressed)

    I would try to convert it to a date and report if the conversion failed or if you you language has a check date function use that.

提交回复
热议问题