I have a basic HTML input field (for phone numbers), that currently lets the user type and submit whatever they want inside:
923-98-Ilovekittens :3
However, I want the field to look like this:
+1 (___)-___-____
And as the user types digits from 0-9, I want those gaps to be filled:
+1 (748)-55_-____
How do I accomplish this with Javascript (and if easier, a Javascript library)?
2
Answers
I guess you can use some input mask library, like this one: https://imask.js.org/.
The third example on their page might work for you.
You can use an input mask library like
Inputmask
by including theInputmask
library in your HTML fileAnd apply the input mask to the input field