2

I'm in need to add input mask for some input fields using PrimeFaces p:inputMask and BootsFaces p:inputText. The required mask should only accept Arabic letters plus some numbers. my problem is: I do not know how to do that, any help will be appreciate.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Hasan
  • 33
  • 5
  • Thanks Jasper de Vries But I think that input mask used to governs what a user is allowed to enter in as input in a text box. It can be said to be a template, or set format that entered data must conform to, mainly used for the purposes of data integrity by preventing transcription errors. – Hasan Mar 05 '18 at 09:53
  • I 'un-bolded' your question – Kukeltje Mar 05 '18 at 19:14
  • Please add a feature request at our [bug tracker](https://github.com/TheCoder4eu/BootsFaces-OSP/issues). If @JasperdeVries is right, I can't promise we can solve the issue, but the minimum we can do is to forward your request to the JavaScript library we've used to implement the input masks. – Stephan Rauh Mar 06 '18 at 22:58
  • 1
    @StephanRauh The only possibility I see (BootsFaces) is regexp which might already work. https://github.com/RobinHerbots/Inputmask#via-inputmask-class https://github.com/TheCoder4eu/BootsFaces-OSP/blob/master/src/main/java/net/bootsfaces/component/inputText/InputTextRenderer.java#L319 `{ regex: "insertRegExpHere" }`. I'll check if it works. If not, then I can probably add / fix it. – Jasper de Vries Mar 06 '18 at 23:28

1 Answers1

2

Arabic characters can be matched using a regular expression. See Include Arabic characters in JavaScript regular expression?

BootsFaces

1.3 and up

BootsFaces 1.3 and up supports a regular expression in the mask like:

<b:inputText mask="{ regex: '[0-9\u0600-\u06FF]*' }" />

Before 1.3

BootsFaces ships with Inputmask by Robin Herbots. Before 1.3 the mask attribute in b:inputText only allows you to pass a mask expression. In a mask expression you cannot use regular expressions. However, the Inputmask library does support regular expressions. You could create a workaround by omitting the mask attribute in b:inputText, and initialise the mask using JavaScript:

Inputmask({ regex: "[0-9\u0600-\u06FF]*" }).mask("input[type=text]");

0-9 is for matching the numbers, \u0600-\u06FF is for matching the Arabic characters.
With .mask("...") you can select the inputs where the mask should apply.

PrimeFaces

Up to this point (6.2) PrimeFaces inputMask does not support a regular expression. You could use p:inputText with p:keyFilter though:

<p:inputText>
  <p:keyFilter regEx="/[0-9\u0600-\u06FF]/"/>
</p:inputText>

Please note that PrimeFaces is using the JavaScript notation: /pattern/.

Other languages

Your question is how to match Arabic characters in masks. Of course the same solution can be applied for other languages using non Western Latin characters, like:

  • Chinese
  • Hebrew
  • Hindi
  • Japanse
  • Korean (Hangul)
  • Russian (Cyrillic)

For each language / character set it is a matter of finding the right regular expression.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • 1
    Just a little confirmation from the BootsFaces team: the addition Jasper describes has officially been integrated into the next version of BootsFaces. Thanks, Jasper, for contributing the code! – Stephan Rauh Mar 09 '18 at 22:27
  • @Hasan, please read "[What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers)" – Jasper de Vries Mar 12 '18 at 06:53
  • But when tried to applied your solution in bootsfaces it is not working and I failed to figure out what is wrong. I added the suggested solution to my page as follows: – Hasan Mar 12 '18 at 06:57
  • – Hasan Mar 12 '18 at 07:03
  • by the way I can not find the bootsfaces release you mentioned above. I only find BootsFaces 1.2.0 not BootsFaces 1.2.1 – Hasan Mar 12 '18 at 07:11
  • The ID in your script is wrong. It is prefixed withe the form's ID. 1.2.1 is not out yet. Use the DOM inspector to find the rendered HTML ID. I just provided the fix this week: https://github.com/TheCoder4eu/BootsFaces-OSP/issues/920 – Jasper de Vries Mar 12 '18 at 07:40
  • @Hasan BootsFaces 1.3.0 (containing this feature) is released! – Jasper de Vries Jul 19 '18 at 07:16