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:
array(
'username',
'match',
'pattern'=>'/^(admin/idiot/root).*$/',
'not'=>true,
'message'=>'This username is not allowed'
).
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:
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.