Всем привет, пытаюсь прикрутить валидатор http://www.yiiframework.com/doc-2.0/yii-validators-regularexpressionvalidator.html
Пишу
$validator = new RegularExpressionValidator();
$validator->pattern = '/[^а-яА-Я.,!()0-9 ]/u';
Получаю
Почему ?
Всем привет, пытаюсь прикрутить валидатор http://www.yiiframework.com/doc-2.0/yii-validators-regularexpressionvalidator.html
Пишу
$validator = new RegularExpressionValidator();
$validator->pattern = '/[^а-яА-Я.,!()0-9 ]/u';
Получаю
Почему ?
class SModelForm extends Model
{
public $s1;
public $s2;
public $s3;
public $s4;
public $s5;
public $s6;
public function rules() {
return [
[['s1', 's2', 's3', 's4', 's5', 's6'], 'match', 'pattern' => '/^\d+(?:\.\d+)?$/', 'message'=>'Only numerical values allowed'],
];
}
}
This is passed as an array and each of these (in this case only one) is processed using
foreach ($this->getActiveValidators() as $validator) {
$validator->validateAttributes($this, $attributeNames);
}
No idea how to use it standalone as you intend to use.
Thanks for your reply, this works
$validator = new \yii\validators\RegularExpressionValidator(['pattern' => '/[^а-яА-Я.,!()0-9 ]/u']);
$validator->not = true;
// etc.