duancai1904 2018-11-19 16:51
浏览 765
已采纳

Laravel时间验证(小时:秒)

Trying to validate an valid 24 hour time.

Request dump,

#parameters: array:6 [▼
  "_token" => "mP2b6fmvlQG6SMgMwz9VI9kZEXtjXqp7hXUjdWdZ"
  "email" => null
  "ageLimit" => null
  "timeFrom" => "0:00"
  "timeTo" => "0:00"
  "alowed_days" => array:7 [▶]
]

Controller validation

    $validation = $request = $request->validate([
        'email' => 'email|required',
        'ageLimit' => 'required|numeric',
        'timeFrom' => 'date_format:H:i',
        'timeTo' => 'date_format:H:i',
    )];

This is failing for some reason? I'm getting "The time from does not match the format H:i."

What am I not understanding?

  • 写回答

2条回答 默认 最新

  • duanbixia7738 2018-11-19 16:55
    关注

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

    G 24-hour format of an hour without leading zeros 0 through 23
    ...
    H 24-hour format of an hour with leading zeros 00 through 23

    The hour values in 0:00 don't have leading zeroes, so H isn't going to match. date_format:G:i should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题