Yii numbers range validator

Hi all,

How do I set the model’s validator so that it will accept input between two number representing latitude, 0 and 90? You cannot have latitude greater than 90 (North Pole).

For example, if user inputs latitude of 114 degrees by mistake, the input will be invalid.

The coordinates are floats, of arbitrary decimal points, eg 89.34632882

			array('latitude', 'in','range'=>/* what to put here? */),

range seems to be supposed to be an array with a list of accepted values, ie ‘range’=array(1,2,3). I wish I could do a ‘max=>90’ and ‘min’=>0 somehow, but this is defined for string length rather than numerical values.

			array('latitude', 'in', 'max'=90, 'min'=>0), //this is wrong of course

Eh, never mind. I solved it, not with “range” but with “compare” which I didn’t expect…

array('latitude', 'compare','operator'=>'<=','compareValue'=>90, 'message'=>'maximum is 90 which is North Pole'  ),

array('latitude', 'compare','operator'=>'>=','compareValue'=>0  ),

You should put an array of values in that place.

array('latitude', 'in','range'=>range(0,90));

There is a CNumberValidator (“numerical” in rules), if the question is still actual :)

why don’t you use “min” and “max” see http://www.yiiframework.com/doc/api/1.1/CNumberValidator

i think that much easier to set ‘min’ => 0 and ‘max’ => 90

I want create a rule for decimal range value 40.000<= score_percentage <=100.000