mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Fix #19735: Fix yii\validators\NumberValidator
to use programmable message for the value validation
This commit is contained in:
@ -15,6 +15,7 @@ Yii Framework 2 Change Log
|
||||
- Chg #19696: Change visibility of `yii\web\View::isPageEnded` to `protected` (lubosdz, samdark)
|
||||
- Bug #19712: Cast shell_exec() output to string for jsCompressor (impayru)
|
||||
- Bug #19731: Fix `yii\data\Sort` to generate proper link when multisort is on and attribute has a default sort order set (bizley)
|
||||
- Bug #19735: Fix `yii\validators\NumberValidator` to use programmable message for the value validation (bizley)
|
||||
|
||||
2.0.47 November 18, 2022
|
||||
------------------------
|
||||
|
@ -116,19 +116,19 @@ class NumberValidator extends Validator
|
||||
protected function validateValue($value)
|
||||
{
|
||||
if (is_array($value) && !$this->allowArray) {
|
||||
return [Yii::t('yii', '{attribute} is invalid.'), []];
|
||||
return [$this->message, []];
|
||||
}
|
||||
$values = !is_array($value) ? [$value] : $value;
|
||||
foreach ($values as $value) {
|
||||
if ($this->isNotNumber($value)) {
|
||||
return [Yii::t('yii', '{attribute} is invalid.'), []];
|
||||
foreach ($values as $sample) {
|
||||
if ($this->isNotNumber($sample)) {
|
||||
return [$this->message, []];
|
||||
}
|
||||
$pattern = $this->integerOnly ? $this->integerPattern : $this->numberPattern;
|
||||
if (!preg_match($pattern, StringHelper::normalizeNumber($value))) {
|
||||
if (!preg_match($pattern, StringHelper::normalizeNumber($sample))) {
|
||||
return [$this->message, []];
|
||||
} elseif ($this->min !== null && $value < $this->min) {
|
||||
} elseif ($this->min !== null && $sample < $this->min) {
|
||||
return [$this->tooSmall, ['min' => $this->min]];
|
||||
} elseif ($this->max !== null && $value > $this->max) {
|
||||
} elseif ($this->max !== null && $sample > $this->max) {
|
||||
return [$this->tooBig, ['max' => $this->max]];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user