Pregunta

I've had a working registration/update model, I wanted to expand on my models so I added in a regex to the password field. I have checked the regex works online and even my client side validation shows it works, but the model refuses to save now. I'm not really sure why, could anyone help me out please?

        return array(
        array('firstName, lastName, email, password', 'required'),
        array('firstName', 'length', 'max'=>45),
        array('lastName', 'length', 'max'=>80),
        array('email', 'length', 'max'=>120),
        // email must be valid email
        array('email', 'email'),    
        // email must be unique
        array('email', 'unique'),
        // Regex for password
        array('password','match', 'pattern'=>'/^[a-z0-9_-]{7,20}$/i', 
            'message'=>'The password must be between 7 and 20 characters
             long'),


        array('password', 'length', 'min'=>7, 'max'=>64),
        array('date_modified', 'safe'),
        array('active, date_modified', 'default', 'setOnEmpty' => true, 'value' => null),
        array('id, first_name, last_name, email, pass, active, date_created, date_modified, live', 'safe', 'on'=>'search'),

    );

Thanks

Jonny

¿Fue útil?

Solución

You can create your own validation rule.

http://www.yiiframework.com/wiki/168/create-your-own-validation-rule/

Or else you can define validation rule in YII Model, something like this:

return array(
    array('password', 'length', 'min'=>7, 'max'=>64),
    array('password','pattern'=>'/^[A-Za-z0-9_!@#$%^&*()+=?.,]+$/u', 'message'=>'Spaces or given characters are not allowed'),
);

There are more validation you can specify in your model.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top