我正在尝试制作日期正则表达式验证器.我遇到的问题是我正在使用带有"date"类型的输入字段,它在Chrome中的功能就像一个魅力; 它在Chrome中打开了一个日历,但在其余部分它什么也没做,所以我决定手动输入其余的日期.
这是我的错误抛出消息(我正在寻找YYYY-MM-DD格式):
$date_regex ='#^(19|20)\d\d[\- /.](0[1-9]|1[012])[\- /.](0[1-9]|[12][0-9]|3[01])$#';
$hiredate = $_POST['hiredate'];
if (!preg_match($date_regex, $hiredate)){
$errors[] = 'Your hire date entry does not match the YYYY-MM-DD required format.';
}
Run Code Online (Sandbox Code Playgroud)
我知道有很多这方面的例子,但我已经尝试了20个,我无法解决它.也许我错过了什么.
这是输入字段,如果有些相关:
<input type="date" name="hiredate" />
Run Code Online (Sandbox Code Playgroud)