【问题标题】:Laravel Time regexLaravel 时间正则表达式
【发布时间】:2014-05-16 14:58:10
【问题描述】:

使用格式为时间的正则表达式:H:M:S。 (00:00:00)

'Time' => 'regex:/^([01]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)$/',

但出现错误:preg_match(): No ending delimiter '/' found

【问题讨论】:

  • 工作正常:regex101.com/r/cN5qH8。也许您需要删除'regex:' 部分
  • 当使用正则表达式模式时,可能需要在数组中指定规则而不是使用管道分隔符,尤其是当正则表达式包含管道字符时。

标签: regex validation time laravel


【解决方案1】:

使用date_format 验证规则要容易得多。

例如

'timeField' => 'required|date_format:H:i',

【讨论】:

    【解决方案2】:

    使用数组代替字符串,用管道作为分隔符:

    'Time' => array('regex:/^([01]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)$/'),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多