Welcome Guest, Not a member yet? Register   Sign In
validation problem
#1

[eluser]Skuja[/eluser]
Good morning every one!

I have following form input line:
Code:
<td colspan="2">Valodas kods &lt;input name="code" type="text" value="&lt;?=$this-&gt;validation->code;?&gt;" maxlength="2"></td>
my validation rules for this input:
Code:
$rules['code'] = "trim|max_length[2]|xss_clean";
The problem is that it all works fine (ie. the validation passes) with latin symbols, but when I type in non latin simbols e.g. ลกลก I get following error:
Quote:The language code field can not exceed 2 characters in length.
Can someone help to make validation rule for none latin symbols ?
#2

[eluser]alex-and-r[/eluser]
The same problem for me. I use Russian symbols and the same rule: "max_length". This rule is set to 3 for me and even if I enter a word of 4 russian letters I get the message that my input is too short.

So how can this be fixed?

Seems that ther no replies to this thread almost for a year. But may be bumping it with my post will help? Smile

UPDATE: It seems that the author of this topic have found some kind of solution here. But in that topic it's said that it's not a solution any way. So can anybody help?
#3

[eluser]Teks[/eluser]
@alex-and-r: the solution shown in that topic IS a valid solution - that is, developing your own validation callback function, using mb_strlen() instead of strlen(). What the author there says is *not* a solution is having to 'wait for php6'! :-)
#4

[eluser]fensen[/eluser]
This can be solved using a callback function.

Code:
$rules['code'] = "trim|callback_code_check|xss_clean";
.
.
.
function code_check($str)
{
  if (mb_strlen($str, "UTF-8") > 2)
  {
    $this->validation->set_message('code_check', 'Code can not exceed 2 chars');
    return false;
  }
  else return true;
}

Please remember to change "UTF-8" to whatever you need.
#5

[eluser]alex-and-r[/eluser]
[quote author="fabian_o" date="1229325035"]This can be solved using a callback function.

...

Please remember to change "UTF-8" to whatever you need.[/quote]

Thank you very much for the reply and for posting actual code. I'll try it!
#6

[eluser]alex-and-r[/eluser]
Well, I tryed the code and it didn't work... Sad

It's funny and strange, but ordinary strlen function works fine for me. No need for mb_strlen or even iconv_strlen. May be it's because I'm using win1251 encoding and not utf8?

But anyway, my problem is solved.




Theme © iAndrew 2016 - Forum software by © MyBB