vaadin-component-factory / input-mask

Vaadin Flow integration of imaskjs library.
Apache License 2.0
1 stars 5 forks source link

How to set a regular expression? #5

Open mil3stone opened 1 year ago

mil3stone commented 1 year ago

I can't find a way to pass a regular expression. Have tried it similar to the default imask.js example from https://imask.js.org/guide.html#masked-base

const digitsMask = IMask(element, {
  mask: /^\d+$/
});

but unfortunately, one can neither pass this /^\d+$/ shortcut nor a RegExp object like new RegExp("^\d+$") via InputMaskOption.option.

Am I missing something to pass a regular expression or is this a future task? I mean, this add-on is declared as EXPERIMENTAL / TESTED in the vaadin directory , so the chance of "not implemented yet" is pretty high.

jcgueriaud1 commented 1 year ago

You need to use the parameter evalMask. For example:

InputMask inputMask = new InputMask("/^\\d+$/", true);
jcgueriaud1 commented 1 year ago

Can you check if it's working? I also updated this ticket https://github.com/vaadin-component-factory/input-mask/issues/3 to add the Regexp case since it's not easy to use.

mil3stone commented 1 year ago

Yes! By using the parameter evalMask I can now reproduce the simple example from imask.js.org