• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
validation problem

Good morning every one!

I have following form input line:
<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:
$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 ?

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?

@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'! :-)

This can be solved using a callback function.

$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.

[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!

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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.