Codeigniter min_length[] not working
I have this code:
$this->form_validation->set_rules('quadra_numero', 'Quadra número', 'required|trim|numeric|xss_clean|min_length[3]|max_length[3]|callback_valida_quadra_setor');
The max_length[3]
works but not the min_length[3]
.
I've checked the returned value with strlen($quadra_numero)
and it returns me 2 characters but the validation seems to ignore it.
In my form I have the number 091, in my database it is a VARCHAR to keep the 0 that is ne开发者_运维百科cessary.
If I post 0912 it will return the error for max_length but if I change it to 91 will pass the validation.
If I post 09 it will work, only with the 0(zero) is removed it won't work.
Any ideas?
Thanks in advance for any help.
--EDIT I have tried to use exact_length[8] and got the same results. The problem is with the 0(zero).
Just at a first glance, you probably need to typecast the variable to a string before sending it in.
$quadra_numero = (string)$quadra_numero;
or
$quadra_numero = strval($quadra_numero);
and see if that takes care of the problem. The strlen is converting the variable to a string before it checks the length, but the validation probably isn't
精彩评论