I want create a rule for decimal range value 40.000<= score_percentage <=100.000
array('entrance_score', 'compare','operator'=>'<=','compareValue'=>100, 'message'=>'Maximum Entrance Score should be 100.' ),
While testing from GUI, it make acceptable the decimal number less than 100 but cannot make acceptable more or equal to 40.000.
The following rule is not working properly, so what should I do?
array('entrance_score', 'compare','operator'=>'>=','compareValue'=>0 , 'message'=>'Minimum Entrance Score should be 40.' ),
So, you want to place a check so that entrance_score
value is between 40.000
and 100.000
, right ?
You could just place a min
, max
rule in your model, something like:
array('entrance_score', 'numerical', 'integerOnly'=>false, 'min'=>40, 'max'=>100),
or, you could create your own custom validation rule, like:
public function rules()
{
return array(
//............
array('entrance_score', 'numerical', 'integerOnly'=>false),
array('entrance_score', 'authenticate'),
//.....
);
}
and your authenticate
function:
public function authenticate($attribute,$params)
{
if($this->entrance_score < 40) {
$this->addError('entrance_score','Minimum Entrance Score should be 40.');
} elseif($this->entrance_score > 100) {
$this->addError('entrance_score','Maximum Entrance Score should be 100.');
}
}
that should do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With