PHP日期格式正则表达式检查
问题描述:
我正在尝试使用PHP正则表达式验证日期字段 YYYYMMDD
。我尝试过这样的事情
i am trying to valdiate the date field "YYYYMMDD
" using PHP regex. I tried something like this
/([0-9]{4})([0-9]{2})([0-9]{2})/
,但在此示例中,它将接受任何两位数字,例如MM或DD的01-99,但我希望MM的01-12和DD的01-31。对此有任何建议吗?
but in this one, it's going to accept any two digits like 01-99 for MM or DD, but i am looking to have something for 01-12 for MM and 01-31 for DD. Any advise on doing this?
谢谢
答
而不是正则表达式,您还可以拆分字符串并使用 检查日期
以查看日期是否有效。
Instead of regular expressions you can also split the string and use checkdate
to see if the date is valid.