Cristal
Cristal

Reputation: 502

Minimum number validator is not working in Yii2 model

[['price'], 'integer', 'min' => 0, 'tooSmall' => 'Price cannot be less than 0'],

I have above rule in my model file. But while validating the model, return is true while passed NULL as price.

Any reason to this?

Upvotes: 0

Views: 874

Answers (1)

Insane Skull
Insane Skull

Reputation: 9358

Set skipOnEmpty to false if you want to validate even when field empty, (by default it is set to true).

[['price'], 'integer', 'skipOnEmpty' => false, 'min' => 0, 'tooSmall' => 'Price cannot be less than 0'],

Upvotes: 2

Related Questions