Inputmask: Mask with two optional parts doesn't work as expected

Created on 16 Jun 2017  路  1Comment  路  Source: RobinHerbots/Inputmask

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?

Most helpful comment

I was able to find a workaround with multiple masks:

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

>All comments

I was able to find a workaround with multiple masks:

$("input").inputmask({
  "mask": ["999-9999","(999) 999-9999[ x9{1,5}]"],
  "greedy": false
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

TiGR picture TiGR  路  3Comments

SujayKrishna picture SujayKrishna  路  7Comments

osaris picture osaris  路  6Comments

toxpal picture toxpal  路  6Comments

drolsen picture drolsen  路  3Comments