【问题标题】:Complex regular expression routing filter wildcard Laravel 5.4复杂正则表达式路由过滤器通配符 Laravel 5.4
【发布时间】:2017-03-22 11:32:01
【问题描述】:

我尝试过滤我的路线,如下所示:

Route::post('/vote/{bandId}', 'VoteController@vote')->where('bandId', '[0-9]+');

但它允许以下路线:

http://localhost/vote/0

这是我不想要的,因为我通过过滤自动增量字段(大于 0)从查询中获取资源。

我尝试像使用preg_match() 一样键入高级正则表达式:

Route::post('/voter/{bandId}', 'VoteController@vote')->where('bandId', '[1-9][0-9]*');

这让数字介于 1 和无限之间。

问题

这最后一条路线不起作用,我如何在获取数据库中的资源之前使用复杂的正则表达式来检查通配符的完整性?

【问题讨论】:

    标签: regex routing laravel-5.4


    【解决方案1】:

    试试下面的正则表达式:

    ^[1-9]\d*$

    来源: What is the regex for "Any positive integer, excluding 0"

    【讨论】:

      猜你喜欢
      • 2015-09-13
      • 1970-01-01
      • 1970-01-01
      • 2014-06-13
      • 2016-10-10
      • 2011-11-05
      • 1970-01-01
      • 1970-01-01
      • 2013-01-30
      相关资源
      最近更新 更多