How to specify a validation rule in Yii2 which will be greater than or less than of a specific number or value?
It should be:
['x', 'compare', 'compareValue' => 100, 'operator' => '<'],
and
['x', 'compare', 'compareValue' => 100, 'operator' => '>='],
accordingly.
Read more in official docs.
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.