|
|
@ -9,6 +9,9 @@ namespace yii\validators; |
|
|
|
|
|
|
|
|
|
|
|
use Yii; |
|
|
|
use Yii; |
|
|
|
use yii\base\InvalidConfigException; |
|
|
|
use yii\base\InvalidConfigException; |
|
|
|
|
|
|
|
use yii\helpers\Html; |
|
|
|
|
|
|
|
use yii\helpers\JsExpression; |
|
|
|
|
|
|
|
use yii\helpers\Json; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* RegularExpressionValidator validates that the attribute value matches the specified [[pattern]]. |
|
|
|
* RegularExpressionValidator validates that the attribute value matches the specified [[pattern]]. |
|
|
@ -81,11 +84,6 @@ class RegularExpressionValidator extends Validator |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function clientValidateAttribute($object, $attribute) |
|
|
|
public function clientValidateAttribute($object, $attribute) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$message = strtr($this->message, array( |
|
|
|
|
|
|
|
'{attribute}' => $object->getAttributeLabel($attribute), |
|
|
|
|
|
|
|
'{value}' => $object->$attribute, |
|
|
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$pattern = $this->pattern; |
|
|
|
$pattern = $this->pattern; |
|
|
|
$pattern = preg_replace('/\\\\x\{?([0-9a-fA-F]+)\}?/', '\u$1', $pattern); |
|
|
|
$pattern = preg_replace('/\\\\x\{?([0-9a-fA-F]+)\}?/', '\u$1', $pattern); |
|
|
|
$deliminator = substr($pattern, 0, 1); |
|
|
|
$deliminator = substr($pattern, 0, 1); |
|
|
@ -100,10 +98,17 @@ class RegularExpressionValidator extends Validator |
|
|
|
$pattern .= preg_replace('/[^igm]/', '', $flag); |
|
|
|
$pattern .= preg_replace('/[^igm]/', '', $flag); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return " |
|
|
|
$options = array( |
|
|
|
if (" . ($this->skipOnEmpty ? "$.trim(value)!='' && " : '') . ($this->not ? '' : '!') . "value.match($pattern)) { |
|
|
|
'pattern' => new JsExpression($pattern), |
|
|
|
messages.push(" . json_encode($message) . "); |
|
|
|
'message' => Html::encode(strtr($this->message, array( |
|
|
|
|
|
|
|
'{attribute}' => $object->getAttributeLabel($attribute), |
|
|
|
|
|
|
|
'{value}' => $object->$attribute, |
|
|
|
|
|
|
|
))), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
if ($this->skipOnEmpty) { |
|
|
|
|
|
|
|
$options['skipOnEmpty'] = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
"; |
|
|
|
|
|
|
|
|
|
|
|
return 'yii.validation.regularExpression(value, messages, ' . Json::encode($options) . ');'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|