Home > Form Elements > Easy Input Mask JavaScript Library – MaskerJS
Easy Input Mask JavaScript Library – MaskerJS

Easy Input Mask JavaScript Library – MaskerJS

A simple JavaScript library for masking HTML input fields.

app.html:

<input id="tel" type="tel" placeholder="+1-234-567-8900">

app.js:

var Masker = require('maskerjs');

var telMask = new Masker(
    [
        '___-____',            // local
//      '____-____',           // local 8
        '(___) ___-____',      // area
//      '(__) ____-____',      // area 8
        '+_-___-___-____',     // international
//      '+_-__-____-____',     // international 8
    ],
    /^[0-9]$/ // allowed chars
);

var telInput = document.getElementById('tel');

telMask.bind(telInput);
// telMask.unbind(telInput);

var val = telMask.unmask(telInput.value).text
  Website Demo

About Shailja Sharma