Jonnny
Jonnny

Reputation: 5039

Yii min length validator allowing blank inputs

I have the following code within a model

rules()
{
....
array('new_pass', 'length', 'min'=>6, 'max'=>64, 'tooShort'=>'Password is too short (minimum is 6 characters)'),        
....    
}

When I input a value that is between 1 and 5 chars long it errors saying it is too short. But if I leave it blank it updates? I'm not sure how to fix this or more importantly why it would let a blank value in.

I tried adding in a allowEmpty, that stopped it updating a password that was 0 length in chars but when I tried to then save the model with a 6+ length password it then error'd saying Password too short'

Any help greatly appreciated

Jonny

Upvotes: 3

Views: 4567

Answers (2)

ineersa
ineersa

Reputation: 3435

As i understand its changepassword action so just add rule:

rules()
{...
array('new_pass','required','on'=>'youraction')
...}

But still 'allowEmpty'=>false' must work for this.

Upvotes: 4

5z- -
5z- -

Reputation: 161

you didn't add tooLong, then try it again

Upvotes: 0

Related Questions