Exposed number normalization as StringHelper::normalizeNumber()

This commit is contained in:
Alexander Makarov
2017-01-15 22:46:25 +03:00
parent eee7b9663c
commit ebe30bd5ee
2 changed files with 24 additions and 2 deletions

View File

@@ -8,6 +8,7 @@
namespace yii\validators;
use Yii;
use yii\helpers\StringHelper;
use yii\web\JsExpression;
use yii\helpers\Json;
@@ -86,7 +87,7 @@ class NumberValidator extends Validator
}
$pattern = $this->integerOnly ? $this->integerPattern : $this->numberPattern;
if (!preg_match($pattern, $this->getStringValue($value))) {
if (!preg_match($pattern, StringHelper::normalizeNumber($value))) {
$this->addError($model, $attribute, $this->message);
}
if ($this->min !== null && $value < $this->min) {
@@ -106,7 +107,7 @@ class NumberValidator extends Validator
return [Yii::t('yii', '{attribute} is invalid.'), []];
}
$pattern = $this->integerOnly ? $this->integerPattern : $this->numberPattern;
if (!preg_match($pattern, $this->getStringValue($value))) {
if (!preg_match($pattern, StringHelper::normalizeNumber($value))) {
return [$this->message, []];
} elseif ($this->min !== null && $value < $this->min) {
return [$this->tooSmall, ['min' => $this->min]];