Correct Regular expressions to match a date

后端 未结 11 647
不知归路
不知归路 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:24

    If you want something simple that does a little more than just validates format, but doesn't go as far as validating how many days is in the month that is entered, or leap years, you can use this:

    ^(19|20)[0-9]{2}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$
    

    This example allows years 19xx and 20xx

提交回复
热议问题