Home >Backend Development >PHP Tutorial >PHP用正则表达式 判断是否为Y-m-d 时间格式

PHP用正则表达式 判断是否为Y-m-d 时间格式

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:27:061292browse

目前的是
if(ereg("^(19|20)\d{2}-(0?\d|1[012])-(0?\d|[12]\d|3[01])$",$sDate))

这样只能是YYYY-MM-DD的格式

如果我要用YYYY-M-D的格式怎么写呢?


回复讨论(解决方案)

同样能支持 YYYY-M-D 格式!
虽然你有意张冠李戴([0-9] 写成 \d)

多谢版主的回复!是我自己的用错函数了,
这个ereg不能这样使用,多谢版主的提醒!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PhpStorm中文教程Next article:Wdcp升级Php5.3成功