RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.4k stars 2.16k forks source link

Mask with two optional parts doesn't work as expected #1622

Open mattsones opened 7 years ago

mattsones commented 7 years ago

I'm trying to mask a 7 or 10 digit phone number with an optional extension.

Goal:

input --> result 1234567 --> 123-4567 1234567890 --> (123) 456-7890 12345678901234 --> (123) 456-7890 x1234

Here's my attempt:

$("input").inputmask({
            "mask": "[(999) ]999-9999[ x99999]",
            // "numericInput": true,
            "skipOptionalPartCharacter": " ",
            "greedy": false
        });

Result 1234567 --> (123) 456-7___ 1234567890 --> (123) 456-7890 12345678901234 --> (123) 456-7890 x1234

If I turn numeric input on, I get the reverse problem: 1234567 --> _-12 x34567 1234567890 --> __1-2345 x67890 12345678901234 --> (_12) 345-6789 x01234

How can I get the desired result?

mattsones commented 7 years ago

I was able to find a workaround with multiple masks:

$("input").inputmask({
  "mask": ["999-9999","(999) 999-9999[ x9{1,5}]"],
  "greedy": false
});