【发布时间】:2021-08-09 17:09:23
【问题描述】:
我从请求中得到了这些数据:
{
"type": "custom",
"start_week": "2020-W19"
}
我的验证规则是:
return [
'type' => 'required|in:standard,custom',
'start_week' => 'required|date_format:Y-\WW',
];
这给了我这个结果:
"errors": {
"start_week": [
"The start week does not match the format Y-\\WW."
]
}
我之前使用这种格式来验证周类型输入,例如“2020-W19”。
我做错了什么,我该怎么办?
【问题讨论】:
-
第一个W一定要转吗?
-
@shaedrich 是的,否则它将获得周数而不仅仅是字母;第一个 W 只是格式中的字母,第二个 W 是周数。
标签: laravel laravel-8 laravel-validation