我正在开发 Laravel 4.2。我尝试使用 Validator 使用正则表达式验证名称字段,这是我的规则如下:
public static $rules_save = [
'class_subjects' => 'required|regex:/[0-9]([0-9]|-(?!-))+/'
];
但是,一旦我调用要验证的规则,就会引发错误,请参见下文:
preg_match(): No ending delimiter '/' found
最佳答案
因为你的正则表达式中有一个管道,你必须使用一个数组:
public static $rules_save = [
'class_subjects' => ['required', 'regex:/[0-9]([0-9]|-(?!-))+/'],
];
来自 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.
关于php - Laravel preg_match() : No ending delimiter '/' found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32810385/