Hi, it is very easy to apply data validation rules in Yii.
..
..
..
..
..
..
Write validation rules in the Model file. e.g.
public function rules() {
return array(
);
}
1) Required Validation
array('name', 'required'),
2) Unique Record Validation
array('name', 'unique'),
3) Url Validation
array('website_url', 'url'),
4) Safe Data Validation
array('address','safe'),
5) Integer Validation
array('zip_code', 'numerical', 'integerOnly' => true),
6) Max Length Validation
array('name, contact_person', 'length', 'max' => 250),
7) Password Retype Validation
array('password', 'compare', 'compareAttribute'=>'password_repeat', 'on'=>'register'),
8) File Extension Validation
array('photo', 'file', 'types'=>'jpg, gif, png'),
—
So you can integrate different types of rules like this
public function rules() {
return array(
array('name', 'required'),
array('name', 'unique'),
array('company', 'numerical', 'integerOnly' => true),
array('email_address', 'email'),
array('website', 'url'),
array('name, email_address, website', 'length', 'max' => 250),
array('contact_number', 'length', 'max' => 100),
array('id, name, email_address, contact_number, website, address, date, company', 'safe', 'on' => 'search'),
);
}

