Validation: Problem with length on textfields

Hi,

I have a problem with validation of textfields.

Example:

A model contains an attribute called "USERNAME". The validation rule looks like that:


array('USERNAME','length', 'max'=>15),

The application generates an form, using an ActiveTextField for attribute USERNAME an Yii generates the following HTML code:


<input type="text" maxlength="15" id="Model_USERNAME" name="Model[USERNAME]"> 

As you can see "maxlength" is taken from the validation rule. Everythnig works fine as long as u use typical ASCII letters (a-zA-Z0-9).

A problem occurs, if you use multibyte-chracter, such es ä,ö,é,ß and so on.

The text field still allowed 15 letters, so it doesn’t matter if you type

Ronald McDonald

or

Rüdiger Bergers

or

André Leromanés

But the validation returns "false" for "Rüdiger Bergers" or "André Leromanés"…i think because of the multibyte characters. "Rüdiger Bergers" is 16 Bytes long, "André Leromanés" 17 Bytes

Is there a way to enable "validation for attributes with multibyte characters"?

Or is there an idea for an workaround?

…or is this a bug of yii?

Thank you,

rall0r.

Check CStringValidator::encoding. mb_string extension is needed to make it work.


array('USERNAME','length', 'encoding' => 'UTF-8', 'max'=>15),

You can also do


mbstring.func_overload = 7

in php.ini. Then strlen and most other relevant string functions work automatically as the mb_* equivalents.

Yeah…

thank you so much! That’s it!

let’s say: :unsure: Read first, then ask… sorry.

>in php.ini. Then strlen and most other relevant string functions work automatically as the mb_* equivalents.

Oh, that’s also very interesting…

Thank you,

rall0r