I have a model with a validation rule like:
[['x'], 'integer'],
[['x'], 'unique'],
Now how can I add a rule like:
x < 100
or something like
x >= 100
I have a model with a validation rule like:
[['x'], 'integer'],
[['x'], 'unique'],
Now how can I add a rule like:
x < 100
or something like
x >= 100
It should be:
['x', 'compare', 'compareValue' => 100, 'operator' => '<'],
and
['x', 'compare', 'compareValue' => 100, 'operator' => '>='],
accordingly.
Read more in official docs.
['x', 'compare', 'compareValue' => 100, 'operator' => '>=' , 'message'=>'Hi To all'],
. But not working. Do you have any idea? –
Meave You could also use the min
attribute on number, or integer validators:
['age', 'integer', 'min' => 0],
['amount', 'number', 'min' => 0],
There is also a max
option.
Yii2 greater than validation :
field_to must be greater than "field_from".
Field 1 : field_from
Field 2 : field_to
[['field_to'], 'compare', 'when' => function($model) {
return $model->builtup_area != null;
}, 'whenClient' => "function (attribute, value){
return $('#form-field_from').val() != '';
}", 'compareAttribute' => 'field_from', 'operator' => '>', 'type' => 'number'],
© 2022 - 2024 — McMap. All rights reserved.