Add "not" property to some validators to invert their rule

I hope i didn’t miss any existing feauture. But i think, for some validators it would make sense to have a “not” (or maybe “negate” or “invert”) property with default: false. If we configure this property to “true” the result of the validation logic is inverted.

Validators where this would make sense:

CRegularExpressionValidator - Attribute must not match

CCompareValidator - Attribute must not be the same

CRangeValidator - Attribute must not be in range

There may be more.

So a rule could look like:






  'message'=>'This username is not allowed'


What do you think, makes sense?

I used to write my own validation method, but your idea is much better and would save me some time. I vote YESSSSSS :)


We seem to be the only two, who find this useful :)

i like the idea too… especially i looked for "not safe" (when i want to say a specific variable should be only integer but is not safe for mass-assginment)

perhaps it would be also nice to have a fileupload working with not:

"not php, phtml, php5, py…"

+1 from me :)


You’ve seen the ‘unsafe’ rule? Sometimes the convention “attributes that have a rule in a scenario are always safe” is making me trouble, too. Like you said, i also have rules that should apply in all scenarios (e.g. type validation) but that doesn’t mean, the attribute is also safe in all scenarios. But that’s another topic…

I’ll open a feature request ticket for the “not” property now.

Here we go:

hey Mike, check this out :

Yii 1.1.5 : Added ‘not’ property to CRangeValidator and CRegularExpressionValidator in order to support inversion of the validation logic (Y!!)

cool !8)