douyong4842 2015-11-05 12:00
浏览 16

指定起始端时正则表达式不匹配

I have the following regex expression in PHP

/^(\d{4}-(\d{4})?)$/

I want match only a string like this

1998-
1998-2015

I am using it in laravel validation like so:

'release_year' => 'required|regex:/^(\d{4}-(\d{4})?)$/'

Nothing else should match and number should be a 4 digit number. But it doesn't seem to be working.

  • 写回答

1条回答 默认 最新

  • duanjiaren8188 2015-11-05 12:59
    关注

    In Laravel documentation:

    regex:pattern

    The field under validation must match the given regular expression.

    Note: When using the regex pattern, it may be necessary to specify rules in an array instead of using pipe delimiters, especially if the regular expression contains a pipe character.

    Try this:

    'release_year' => array('required', 'regex:/^(\d{4}-(\d{4})?)$/')
    
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿