mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-12 02:09:48 +01:00
Exposed number normalization as StringHelper::normalizeNumber()
This commit is contained in:
@@ -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]];
|
||||
|
||||
Reference in New Issue
Block a user