0

Using flags with constraint REGEX

asked 2021-04-13 21:00:44 +0800

Bobzk gravatar image Bobzk
442 1 7

See Fiddle_Example

Is it possible to set the flags for a constraint regex?

I want to do something like

/^[\p{L}\p{P}\p{Z}\p{N}\|]{1,32}$/gmu

the /gmu (specifically the "u") are the flags to (hopefully) tell javascript to treat the \p{L} etc as tests for Unicode characters.

It is all to test that a name is valid including umlauts etc.

It does not work and is using the older regex that has no special meaning for \p{L}

delete flag offensive retag edit

Comments

Thanks for pointing me in the right direction.

Bobzk ( 2021-04-14 19:15:02 +0800 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2021-04-14 19:27:50 +0800

Bobzk gravatar image Bobzk
442 1 7

updated 2021-04-14 19:37:18 +0800

Thanks for pointing me in the right direction.

Unfortunately I don't see it ever working unless the ZK SimpleConstraints.js is changed (either by Potix or my own version) as the option flag set by the JS is only the "g" flag. The SimpleConstraints JS simply ignores any supplied flag information (after the final "/") and uses a fixed "g" flag.

this._regex = new RegExp(k >= 0 ? cst.substring(j, k) : cst.substring(j), 'g');

Ideally Potix should accept a change request to support Regexp flags.

There is a possible alternative that does mostly what I want -

Use

inputAttributes="pattern=^[\p{L}\p{P}\p{Z}\p{N}\|]{1,32}$"

on the ZUL. You also need :

input:invalid { background-color: #ffdddd; }

in your CSS.

However as I need anyway to do further validation, I will do all validation at server and show error message as appropriate.

  • I have modified Fiddle to show this : Fiddle*
link publish delete flag offensive edit

Comments

I have posted a feature request https://tracker.zkoss.org/browse/ZK-4863

hawk ( 2021-04-15 11:49:43 +0800 )edit

Thanks Hawk.

Bobzk ( 2021-04-15 20:00:11 +0800 )edit
1

answered 2021-04-14 15:03:09 +0800

hawk gravatar image hawk
2785 1 5
http://hawkphoenix.blogsp... ZK Team

According to your example, it uses javascript regular expression to validate. ZK just calls new RegExp() and validate your input with val.match(regex).

Therefore, what ZK supports is what a browser can support.

You can check the related source:

link publish delete flag offensive edit
1

answered 2021-04-15 12:03:06 +0800

hawk gravatar image hawk
2785 1 5
http://hawkphoenix.blogsp... ZK Team

You can also override that function like

zk.afterLoad('zul.inp', function() {
    var exWidget = {};
    zk.override(zul.inp.SimpleConstraint.prototype, exWidget, {
        _init: function (cst) {
            exWidget._init.apply(this, arguments);
            if (this._regex){
                //create your own RegExp
            }
        },
    });
});
link publish delete flag offensive edit

Comments

That is a useful bit of advice/information - I will keep for future reference. Thanks.

Bobzk ( 2021-04-15 20:00:53 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2021-04-13 21:00:44 +0800

Seen: 13 times

Last updated: Apr 15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More