Monday, April 30, 2018

yii2 compare validation

In this example you can see password and password_again attributes comparing using compare and compareAttribute.

Another example is validates if price is greater than or equal to 5000 using the compare and compareAttribute.

Yii2 Compare validation Rules

[
    // validates "password" attribute equals to "password_again"
    ['password', 'compare'],

    // same as above but with explicitly specifying the attribute to compare with
    ['password', 'compare', 'compareAttribute' => 'password_again'],

    // validates if price is greater than or equal to 5000
    ['price', 'compare', 'compareValue' => 5000, 'operator' => '>=', 'type' => 'number'],
]

1 comment:

  1. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
    Hire Yii Developers in India

    ReplyDelete

Recent Update

yii2 session handling

use yii\web\Session; $session = Yii::$app->session; // start session $session->open(); // close session $session->close(); ...

Most Search