Create your own Validation Rule

Comparing #4 with #9

Content

[...]
The easiest way to create a new validation rule is inside the model that is going to use it.

Let's say that you want to check if a user password is safe enough.
Usually you could achieve this result just by using the [CRegularExpressionValidator](http://www.yiiframework.com/doc/api/CRegularExpressionValidator) but for the sake of this guide let's pretend that validator does not exist.

first of all in your model
class you'll have to add two constants
 
 
```php 
const WEAK = 0;
 
const STRONG = 1;
 
```
 
 
 
then in your 
rules method you'll have to set the rule
[...]
);
}
```

 
 
##Links
 
* Russian version [The PHP Times](http://phptime.ru/blog/yii/27.html)