Welcome Guest, Not a member yet? Register   Sign In
[SOLUTION FOUND]Validation library has incorrect length rules for non-latin utf8 characters
#1

[eluser]Skuja[/eluser]
Validation library length rules returns invalid length for non-latin utf8 characters.
For example if i set rule max_length[2] for a field and try to validate data: "šķ" it returns invalid length error.
Does anybody has good workaround for this, or should i add callback function each time on validation?

EDITED: I replaced native Validation library with my modified version, where i replaced
Code:
strlen($str)
with
Code:
mb_strlen($str,'utf8')
in lines 433, 452, 471. And it works fine.
PS. I have read that mb_strlen function is slow. Maybe anyone has found better solution?
#2

[eluser]xwero[/eluser]
Wait for php6 but that is not a solution Smile I believe there are some php hacks to use unicode strings.
#3

[eluser]alex-and-r[/eluser]
[quote author="xwero" date="1206715268"]Wait for php6 but that is not a solution Smile I believe there are some php hacks to use unicode strings.[/quote]
Why isn't it a solution? Can you explain a bit further? Cuz I have the same problem with russian characters!
#4

[eluser]Skuja[/eluser]
It is a solution, therefore in version 1.7 this problem has been fixed.
#5

[eluser]alex-and-r[/eluser]
[quote author="Skuja" date="1229353660"]It is a solution, therefore in version 1.7 this problem has been fixed.[/quote]

It's strange but I'm using version 1.7 of CI and I get this very problem. May be it's because of the encoding - I'm not using UTF8?
#6

[eluser]Skuja[/eluser]
form_validation uses mb_strlen function only if it available, otherwise standard strlen is used:
Code:
if (function_exists('mb_strlen'))
{
    return (mb_strlen($str) < $val) ? FALSE : TRUE;        
}

return (strlen($str) < $val) ? FALSE : TRUE;
Please check if you have loaded mbstring extension in your php.ini file
this line should be un uncomented:
Code:
extension=php_mbstring.dll




Theme © iAndrew 2016 - Forum software by © MyBB