Laravel preg_match(): No ending delimiter '/' found

断了今生、忘了曾经 提交于 2019-12-17 05:07:20

问题


Im working on Laravel 4.2. Im trying to use Validator to validate a name field with regex, here is my rule below:

 public static $rules_save = [

        'class_subjects' => 'required|regex:/[0-9]([0-9]|-(?!-))+/'
    ];

But as soon as I call the rule to be validated an error is thrown, see below:

preg_match(): No ending delimiter '/' found

回答1:


Since your regex has a pipe in it, you have to use an array:

public static $rules_save = [
    'class_subjects' => ['required', 'regex:/[0-9]([0-9]|-(?!-))+/'],
];

From the docs:

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.



来源:https://stackoverflow.com/questions/32810385/laravel-preg-match-no-ending-delimiter-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!