gpt4 book ai didi

php - Laravel preg_match() : Unknown modifier ']'

转载 作者:行者123 更新时间:2023-12-05 00:49:58 28 4
gpt4 key购买 nike

我在 Laravel 4.2 上工作。我尝试使用验证器通过正则表达式验证名称字段,这是我的以下规则:

public static $rules_save = [
'name' => 'required|regex:/[XI0-9/]+/|unique:classes'
];

但是,一旦我调用要验证的规则,就会引发错误,请参见下文:

preg_match(): Unknown modifier ']'

在以下位置:

protected function validateRegex($attribute, $value, $parameters)
{
$this->requireParameterCount(1, $parameters, 'regex');

return preg_match($parameters[0], $value); // **ON THIS LINE**
}

最佳答案

由于您需要将 / 包含到字符类中,因此您需要转义它:

'name'      => 'required|regex:/[XI0-9\/]+/|unique:classes'
^

或使用其他regex delimiters .

When using the PCRE functions, it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.

Often used delimiters are forward slashes (/), hash signs (#) and tildes (~).

关于php - Laravel preg_match() : Unknown modifier ']' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32807517/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com