Social Icons

Pages

Saturday, May 11, 2013

Yii Model On Insert, Update And Change Password And Alphanumeric password



In Model.php Add this rules
public function rules()
{
        
   return array(
 array('username, password,confirmpassword,firstname,
               lastname, email,address, companyname, usertype,
               isactive',       'required',
               'on'=>'insert'),
        array('username, firstname,lastname, email,address,
        companyname, usertype,isactive', 'required',
              'on'=>'updateuser'),
        array('password,confirmpassword','required',
           'on'=>'changepassword'),
            array('password', 'compare', 'compareAttribute' =>
              'confirmpassword','on'=>'insert,changepassword'),
             
           array('password','passwordalphanumeric',
             'on'=>'changepassword'),   
            
            array('username,password,firstname,lastname,
            email,address,companyname,phoneno,mobileno',
            'filter', 'filter'=>'trim'),
}
public function passwordalphanumeric($attribute_name,$params){
    if(!empty($this->password)){
       if (preg_match('~^[a-z0-9]*[0-9][a-z0-9]*$~i',$this->password)) {
            // $subject is alphanumeric and contains at least 1 number
       } else {   // failed
           $this->addError($attribute_name,'Enter password with digits');
       }       
    }
}


No comments:

Post a Comment