Form validation pattern and utf

Notice: This thread is very old.
kedrigern
Member | 102
+
0
-

Hi,

I am using regexp validation in Nette forms and I have problem with utf.

This is solution for english:

$this->addText("name", "Label:")
 ->addRule(Form::PATTERN, 'Message', '\w*');

But I need general solution (string can contains any utf letter like ěščřžýáíé).

What is the proper way?

David Grudl
Nette Core | 8116
+
0
-

Regexp in Javascript has surprisingly weak unicode support, so you must use something like [a-zA-Z0-9_\\u00A1-\\uFFFF]

MartyIX
Member | 217
+
0
-

You may encounter the following error:

http://stackoverflow.com/…port-l-l-n-p

when using \uhhhh in PHP because PCRE is compiled by default without Unicode support. I used \x{hhhh} and added a line to netteForms.js:

pattern: function(elem, arg, val) {
        // replace \x{1234} -> \u1234
        arg = arg.replace(/\\x\{([a-fA-F0-9]{4})\}/gi, '\\u$1'); // NEW LINE
        try {
                return typeof arg === 'string' ? (new RegExp('^(' + arg + ')$')).test(val) : null;
        } catch (e) {
        }
},

and everything works all right.

Last edited by MartyIX (2015-02-25 19:36)