用于检查日期格式是否正确的php reg表达式

用于检查日期格式是否正确的php reg表达式,php,regex,Php,Regex,我目前正在尝试确定日期的格式是否为YYYY-DD-MM 在PHP中,我得到了以下信息: if (preg_match('(\d{4})(-)(\d{2})(-)(\d{2})$', $newDateOfBirth)) 但是,我不断得到以下错误: 警告:preg_match():中的未知修饰符“(” 第105行的C:\webserver\webroot\index.php 您缺少分隔符: if (preg_match('~(\d{4})(-)(\d{2})(-)(\d{2})$~', $newD

我目前正在尝试确定日期的格式是否为
YYYY-DD-MM

在PHP中,我得到了以下信息:

if (preg_match('(\d{4})(-)(\d{2})(-)(\d{2})$', $newDateOfBirth))
但是,我不断得到以下错误:

警告:preg_match():中的未知修饰符“(” 第105行的C:\webserver\webroot\index.php


您缺少分隔符:

if (preg_match('~(\d{4})(-)(\d{2})(-)(\d{2})$~', $newDateOfBirth))

$
需要进入delimiterOff主题提示,我建议使用或验证日期是否有效。@mario您可以编辑注释,而不是重新发布它们。