<?php
namespace app\components\validators;
use yii\validators\Validator;
class PercentageValidator extends Validator
{
public function validateAttribute($model, $attribute)
{
$percentage = $model->{$attribute};
if (!is_null($percentage) && ($percentage < 0 || $percentage > 100)) {
$model->addError($attribute, 'Should be a value between 0 and 100.');
}
}
}