How to validate email and email already exist or not check, in Yii Framework?

george picture george · Oct 8, 2012 · Viewed 30.7k times · Source

How to validate email using Yii Model validation rules function code. Also how to check email exist or not using Model validation rules function in Yii.

Answer

GBD picture GBD · Oct 8, 2012

You can set your model validations as below

public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
            //First parameter is your field name of table which has email value
        array('email', 'email','message'=>"The email isn't correct"),
        array('email', 'unique','message'=>'Email already exists!'),            
    );
}

Yii Reference Link For More Detail: http://www.yiiframework.com/wiki/56/