4

I want to prepend +90 (Turkey's phone code) to every phone numbers a user enters. For that reason I am using a mask like this:

<p:inputMask
    id="homePhone"
    value="#{personController.model.homePhone}"
    mask="+90 (999) 999-9999"
    size="20"
    converter="converterPhone" />

But displays it like this: +_0 (___) ___-____

However, I want it to look like this: +90 (___) ___-____ <!-- pay attention to 9 -->

Is there a way to escape the first 9 like this: mask="+\90 (999) 999-9999"?

Thank you all...

Ahmet
  • 908
  • 1
  • 17
  • 26
  • doess it work ? – Bilal Dekar Oct 07 '16 at 11:09
  • @Billy Hope, wouldn't it make a system-wide change? I would like to make the least impact (don't wanna effect other devs' code). But it would be nice to have another char (maybe * or #) to represent all digits, instead of 9, though. – Ahmet Oct 07 '16 at 11:15
  • i don't know how it could effect other dev's code, as long as you use javacript only on your own code, anyway # is a good choice, goodluck – Bilal Dekar Oct 07 '16 at 11:37

3 Answers3

5

Number 9 is used as mask for all the digits, if you want to use 9, change the mask using JavaScript, by redefining x as mask :

$.mask.definitions['9'] = '';
$.mask.definitions['x'] = '[0-9]';

Now you can use x as mask, :

<p:inputMask mask="+90(xxx) xxx-xxxx" id="homePhone"  />
Bilal Dekar
  • 3,200
  • 4
  • 28
  • 53
  • It works like a charm (I used # instead of x since i represent x for extensions). Thanks for the answer.. – Ahmet Oct 07 '16 at 11:27
0
const phoneMask = new Inputmask("+886(xxx)xxx-xx-xx");

phoneMask.definitions.x = phoneMask.definitions['9'];
delete phoneMask.definitions[9];

phoneMask.mask(someElement);
  • 3
    Hi Vitalik and welcome to Stack Overflow. Can I ask you not to answer just with only code in the future please. Try to provide a nice description about how your solution works. [See here for help answering.](https://www.stackoverflow.com/help/how-to-answer) Thanks. – Taazar Mar 03 '20 at 11:21
0

When your newly mask is acting strange and replaces some static chars with the mask, then there is a definition which uses the char as symbol. To solve this you need to double escape the char.

Luca
  • 1
  • Hi Luca, could you provide an example of how I would double escape the char please? Thanks. – Taazar Mar 09 '20 at 11:14