Create your own Validation Rule

Comparing #1 with #2

Revision #2 was created by nickcv nickcv on Mar 31, 2011, 9:41:23 AM.

made correction to headers

Content

Some times the core validation rules provided by Yii won't satisfy all your needs, so you'll need to create your very own validation rule. ##Easy approach: inside-model rule
 
================================
  

The easiest way to create a new validation rule is inside the model that is going to use it.
[...]
Add Error accepts two parameters: the first one is the name of the attribute that you want to display the error in your form, the second one is the actual error string you want to be displayed.

##Complete approach: extending the CValidator class
 
=================================================
  

If you need your custom validation rule in more then one model the best thing to do is extending the CValidator class.
Extending this class you also can take advantage of other features, like [CActiveForm::$enableClientValidation](http://www.yiiframework.com/doc/api/1.1/CActiveForm#enableClientValidation-detail), first implemented with Yii 1.1.7 release.

##Creating the class file
[...]