Inputmask

5.0.9 · active · verified Sun Apr 19

Inputmask is a JavaScript library for applying client-side input masks to HTML form elements, ensuring user input conforms to a predefined format such as phone numbers, dates, or currency. It helps guide users, reduces input errors, and improves data consistency. The current stable version is 5.0.9, with updates released as needed for bug fixes, new features, and browser compatibility. A key differentiator is its versatile support for vanilla JavaScript, jQuery, and jqlite, making it adaptable across diverse web projects. The library provides an extensive set of predefined masks and offers robust options for custom mask definitions, including control over placeholders, repeat behavior, and real-time validation, making it a flexible and powerful solution for input formatting.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to apply an input mask to HTML input fields for phone numbers and dates using vanilla JavaScript and the ESM import style.

import Inputmask from 'inputmask';

// Vanilla JavaScript example
document.addEventListener('DOMContentLoaded', () => {
  const phoneInput = document.getElementById('phone-number');
  const dateInput = document.getElementById('date-input');

  if (phoneInput) {
    const phoneMask = new Inputmask('+9 (999) 999-9999');
    phoneMask.mask(phoneInput);
  }

  if (dateInput) {
    // Ensure inputmask.date.extensions is imported for 'datetime' alias
    const dateMask = new Inputmask('datetime', {
      inputFormat: 'dd/mm/yyyy',
      placeholder: 'dd/mm/yyyy'
    });
    dateMask.mask(dateInput);
  }
});

// HTML to go with the above JavaScript:
// <input type="text" id="phone-number" placeholder="+_ (___) ___-____">
// <input type="text" id="date-input" placeholder="dd/mm/yyyy">

view raw JSON →