我想在Laravel中验证一个日期。 我在前端使用datepicker,JavaScript以日期格式dd-MMMM-yy将日期发送到服务器Laravel:
$scope.formData.dob = $filter('date')(scope.formData.dob, 'dd-MMMM-yy');我的laravel有这样的验证:
$validator = Validator::make($postData, [ 'dob' => 'date_format:"dd-MMMM-yy"', ]);但是验证器一直说日期与格式dd-MMMM-yy不匹配:
dob与格式dd-MMMM-yy不匹配。
我想也许它与格式类型有关,所以我尝试将它改为不同的格式,如d / m / y,dd-mm-yyyy等......在JavaScript日期和Laravel日期验证中但是一切都在说同样的错误日期不匹配。 输出似乎很好,它是我在验证中提到的格式。 我不明白为什么Laravel验证失败了。
我在这里错过了什么吗?
I am trying to validate a date in Laravel. I am using datepicker in the frontend where the JavaScript sends the date to the server Laravel in this format dd-MMMM-yy:
$scope.formData.dob = $filter('date')(scope.formData.dob, 'dd-MMMM-yy');My laravel has a validation like this:
$validator = Validator::make($postData, [ 'dob' => 'date_format:"dd-MMMM-yy"', ]);However the validator keeps saying that the date does not match the format dd-MMMM-yy:
The dob does not match the format dd-MMMM-yy.
I thought maybe it has to do with the format type so I tried changing it to different formats like d/m/y, dd-mm-yyyy, etc.. in both JavaScript date and Laravel date validation but everything keeps saying the same error that the date doesn't match. The output seems fine though and it is in the format I have mentioned in validation. I dont understand why Laravel validation fails.
Am I missing something here?
最满意答案
你使用的是错误的格式。 您需要使用标准的PHP格式,这就是Carbon以及Laravel验证所使用的格式。 你可以在PHP Docs中找到它们的date()
我相信,你真正想要的是dFy 。
You're using the wrong format. You need to use standard PHP formats, which is what Carbon and, in turn, Laravel's validation uses. You can find them in the PHP Docs for date()
What you actually want is d-F-y, I believe.
更多推荐
发布评论