mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-21 22:47:17 +01:00
finished validator refactoring.
This commit is contained in:
@@ -51,8 +51,8 @@ class RegularExpressionValidator extends Validator
|
||||
public function validateAttribute($object, $attribute)
|
||||
{
|
||||
$value = $object->$attribute;
|
||||
if ((!$this->not && !preg_match($this->pattern, $value)) || ($this->not && preg_match($this->pattern, $value))) {
|
||||
$message = ($this->message !== null) ? $this->message : \Yii::t('yii|{attribute} is invalid.');
|
||||
if (!$this->validateValue($value)) {
|
||||
$message = $this->message !== null ? $this->message : \Yii::t('yii|{attribute} is invalid.');
|
||||
$this->addError($object, $attribute, $message);
|
||||
}
|
||||
}
|
||||
@@ -64,8 +64,9 @@ class RegularExpressionValidator extends Validator
|
||||
*/
|
||||
public function validateValue($value)
|
||||
{
|
||||
return !$this->not && preg_match($this->pattern, $value)
|
||||
|| $this->not && !preg_match($this->pattern, $value);
|
||||
return !is_array($value) &&
|
||||
(!$this->not && preg_match($this->pattern, $value)
|
||||
|| $this->not && !preg_match($this->pattern, $value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user