How to specify a validation rule in Yii2 which will be greater than or less than of a specific number or value?

Anisur Rahaman Sakib picture Anisur Rahaman Sakib · Mar 31, 2015 · Viewed 8k times · Source

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

Answer

arogachev picture arogachev · Mar 31, 2015

It should be:

['x', 'compare', 'compareValue' => 100, 'operator' => '<'],

and

['x', 'compare', 'compareValue' => 100, 'operator' => '>='],

accordingly.

Read more in official docs.