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

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

WBOY
Release: 2016-06-23 13:27:06
Original
1269 people have browsed it

目前的是
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不能这样使用,多谢版主的提醒!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template