Format Phone Numbers With Vanilla JavaScript – phoneinput.js

Category: Form , Javascript | February 6, 2019
Authorlevidavidmurray
Last UpdateFebruary 6, 2019
LicenseMIT
Views2,582 views
Format Phone Numbers With Vanilla JavaScript – phoneinput.js

phoneinput.js is a vanilla JavaScript plugin which automatically formats the phone numbers typed in an input field using your own pattern.

Basic usage:

Create a normal input field on the web page.

<input id="phoneInput" required autocomplete="off" type="text">

Download and place the JavaScript file phoneinput.js at the end of the document.

<script src="./js/phoneinput.js"></script>

Change the default pattern the entered value must match.

const defaultFormat = '({0}{1}{2}) {3}{4}{5}-{6}{7}{8}{9}';

You Might Be Interested In:


Leave a Reply