javaregexzkzul

Regex not working in zul -ZK


I'm working with Java and ZK. Trying to use a regex as a constraint on a textbox.

This is the regex: ^[0-9]{1,9}(?:\\.[0-9]{1,3})?$. It is working fine in Java but while using in zul textbox, its giving error: Unknown constraint: ^[0-9]{1 Please have a look at the screenshot attached:

enter image description here

Valid values of regex-

121245.121(3 digits after decimal is valid)
2145.11
0.23
5748579

Invalid values-

.111
45445.454545(3 digits after decimal is valid)
-1545.2
22..

Code in zul is as below-

<textbox xmlns:w="client" id="bal" maxlength="12" tooltiptext="Balance" constraint="^[0-9]{1,9}(?:\\.[0-9]{1,3})?$">

ZK Fiddler can be found at : http://zkfiddle.org/sample/2c9e93q/2-Textbox-regex-issue

Can anyone help me solve this issue?


Solution

  • As @RC. mentions in the answer above, the regex delimiters (/<pattern>/) are required in the pattern attribute value to define a regex. However, your regex will allow values like 67\k78 because the \\ defines a literal backslash and a dot stands for any character but a newline.

    The correct regex is

    <textbox constraint="/^[0-9]{1,9}(?:[.][0-9]{1,3})?$/" xmlns:w="client" id="bal" maxlength="12" tooltiptext="Balance">
                         ^              ^^^             ^
    

    Note that no escaping is necessary when the dot is placed into a character class [.].

    See the updated fiddle.

    enter image description here