doubian19900911 2016-12-29 13:21
浏览 70

针对特定格式的laravel中的格式验证

I am trying to get date_format validation going on in my laravel application. Its an api and get datetime in the format

2015-10-09T12:36:576+01:00

It is supposed to be IOS 8601 format so I was checking it against the format "Y-m-d\TH:i:sO" by using

'createdAt'  => "required|date_format:Y-m-d\TH:i:sO",

But the validation fails. I am pretty sure that I am wrong in the format for the date(which I got from the official php documentation meaning the format for the data is not ISO 8601). Could someone please tell me what format that date is in?

Thanks

  • 写回答

1条回答 默认 最新

  • dongpu2476 2017-05-17 20:49
    关注

    Your date format ends with +01:00. You are trying to match with type O which is +0100 (without the colon)

    See the format specs here.

    http://php.net/manual/en/function.date.php

    What's kind of messed up is in laravel, it creates a date object which is able to accurately read your date, but then it tries to render it back to the format you specified (removing the :) and then comparing it to the original, which is obviously different:

    https://github.com/laravel/framework/blob/5.4/src/Illuminate/Validation/Concerns/ValidatesAttributes.php#L363

    This is a problem because technically both of those formats are ISO 8601 compliant.

    评论

报告相同问题?

悬赏问题

  • ¥15 vscode的问题提问
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM