Revision #25 has been created by CedSha on Feb 4, 2013, 5:27:51 AM with the memo:
Add filter validation samples
« previous (#21) next (#26) »
Changes
Title
unchanged
Reference: Model rules validation
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
Form validation, model, validation, reference, validation rules, validator
Content
changed
[...]
### `filter` : [CFilterValidator]
Transforms the data being validated based on a filter.
1. **filter**, the filter method.
*Example:*
With custom function
```php
array('eanupc','filter','filter'=>array($this,'keepProductCode')),
...
public function keepProductCode($eanupc){
return ltrim(substr($eanupc,6,6),'0');
}
```
*NOTE:* The filter validator maybe use with other validators for the same attribute. In this case one must pay attention to the order of the validators list as the filter validator will change the attribute value.
### `in` : [CRangeValidator]
Validates that the attribute value is among the list (specified via range).[...]
4. **strict**, whether the comparison is strict (both type and value must be the same). *(false)*
*Example:*
```php
array('language','in','range'=>array('en','fr','zn'),'allowEmpty'=>false),
```
### `length` : [CStringValidator]
Validates that the attribute value is of certain length.[...]
6. **tooSmall**, user-defined error message used when the value is too small.
*Example:*
```php
array('quantity','numerical',
'integerOnly'=>true,
'min'=>1,
'max'=>250,
'tooSmall'=>'You must order at least 1 piece',
'tooBig'=>'You cannot order more than 250 pieces at once'),
```
### `match` : [CRegularExpressionValidator]
Validates that the attribute value matches to the specified regular expression.
1. **allowEmpty**, whether the attribute value can be null or empty. *(true)*
2. **not**, whether to invert the validation logic. Since Yii 1.1.5. *(false)*
3. **pattern**, the regular expression to be matched with.[...]