views:

656

answers:

1

Hi, I'm having a little issue with a masked input with jquery:

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

Masked-Input-Plugin by Digitalbrush

It's so usefull to mask inputs with non-complex rules, so I used this rule to mask my phonenumber input:

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

Now the problem is when I want to let the user enter two type of phones on the same input, for example, the user can enter a phone number like this:

(02) 222 - 22 - 22

As well as:

(02) 222 - 22 - 2

Now, how should I concatenate this two rules, so that the masked input keeps formatting the input textbox (adding the dashes and parentheses)?

If you know another way or another plugin that could let me get what I want (even if it's without using this plugin), please let me know.

Thanks in advance.

+4  A: 

You can have the last character be optional. Put a question mark in the mask definition right before the character you want to start the optional input.

.mask("(99) 999-99-9?9")
Josh Bush
THANKS A LOT ! just what i was looking for.
lidermin
Lidermin, you should accept the answer if it did what you needed.
Aaron Smith
Sorry, I thought I accepted the answer before.
lidermin