I am trying to create an input receiving and formatting an Israeli phone number. In Israel, we have multiple phone number formats, and I wish the input could identify and format the number correctly. For example, here are a few phone formats here:
Type | Format |
---|---|
Emergency numbers | 10X or 11X or 12XX |
Geographical | (0A) XXX-XXXX |
Cellular and Mobile | 05N XXX-XXXX |
Non-geographical (VoIP) | 07N XXX-XXXX |
Business toll | 1 700 XXX-XXX |
Another business toll | 1 599 XXX-XXX |
Free toll | 1 800 XXX-XXX |
I tried using imask js with dynamic masks.
const mask = {
masks: [
{ mask: '{1}{0}0' },
{ mask: '{1}{1}0' },
{ mask: '{1}{2}00' },
{ mask: '{1} {7}{0}{0} 000-000' },
{ mask: '{1} {5}{0}{0} 000-000' },
{ mask: '{1} {8}{0}{0} 000-000' },
{ mask: '{1} {9}{0}{0} 000-000' },
{
mask: '({0}A) 000-0000',
definitions: {
A: /[23489]/
}
},
{
mask: '05N 000-0000',
definitions: {
N: /[012345689]/
}
},
{
mask: '07N 000-0000',
definitions: {
N: /[1234679]/
}
}
]
}
However, when I type any digit in the input, for example 0
to enter a mobile number, it immediately selects the first mask (emergency) and fills in the following number: 100.