Entrance to the jQuery jellied chamber

I have a little problem with masked input with jquery:

I have phonenumber text input, so I masked it with a small plugin that I got from this site:

Masked-Input-Plugin by Digitalbrush

This is so useful to mask inputs with nonprofit rules, so I used this rule to mask phonenumber input:

$("#txtHomePhoneNumber").mask("(99) 999-99 99"); 

Now the problem is when I want the user to enter two types of phones at the same input, for example, the user can enter the phone number as follows:

(02) 222 - 22 - 22

As well as:

(02) 222 - 22 - 2

Now, how should I concatenate these two rules so that the masked input retains the formatting of the input text field (adding dashes and parentheses)?

If you know another method or plugin that can allow me to get what I want (even if it does not use this plugin), let me know.

Thanks in advance.

+7
jquery jquery-plugins
source share
1 answer

You can use the last character. Place a question mark in the mask definition immediately before the character you want to trigger optional input.

 .mask("(99) 999-99-9?9") 
+13
source share

All Articles