lidermin
lidermin

Reputation: 2832

Jquery masked input

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.

Upvotes: 7

Views: 16037

Answers (1)

Josh Bush
Josh Bush

Reputation: 2718

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")

Upvotes: 13

Related Questions