finished validator refactoring.

This commit is contained in:
Qiang Xue
2013-04-04 10:57:01 -04:00
parent 3bd186deeb
commit 421e31ec0f
6 changed files with 25 additions and 6 deletions

View File

@@ -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));
}
/**