explaingit

igorescobar/jquery-mask-plugin

4,764JavaScriptAudience · developerComplexity · 1/5Setup · easy

TLDR

A tiny jQuery library that automatically formats form fields as users type, inserting separators for phone numbers, dates, credit cards, and any custom pattern you define.

Mindmap

mindmap
  root((jquery-mask))
    What it does
      Format as you type
      Auto-insert separators
      Remove mask on demand
    Mask types
      Numeric
      Alphabetic
      Mixed patterns
      Reverse currency
    Integration
      jQuery
      React and Vue
      Angular and Zepto
    Install
      npm or Bower
      CDN link
      HTML data attributes
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add automatic phone number formatting so users see (555) 123-4567 as they type digits into a contact form.

USE CASE 2

Apply a date input mask so users always enter dates in DD/MM/YYYY format without typing slashes manually.

USE CASE 3

Create a currency field where the decimal point stays fixed as the user types from right to left.

USE CASE 4

Configure input masks directly in HTML using data attributes without writing extra JavaScript.

Tech stack

JavaScriptjQuery

Getting it running

Difficulty · easy Time to first run · 5min
License information not provided in the explanation.

In plain English

jQuery Mask Plugin is a small JavaScript library that controls how users type into form fields on a webpage. It applies a "mask," which is a pattern that formats or restricts input as it is typed. Common examples include phone numbers formatted as (555) 123-4567, dates as 31/12/2024, or credit card numbers split into groups of four digits. The mask takes care of inserting the separators automatically, so the user just types the digits and the field arranges them correctly. The library works by attaching to any form input or HTML element through jQuery, a popular JavaScript utility. You specify the pattern you want using a simple format string, and the plugin handles the rest at the browser level, with no server involved. It supports plain numeric masks, alphabetic masks, and mixed patterns. There is also support for reverse masks, which are useful for currency fields where the decimal point stays fixed as the user types from right to left. Beyond basic formatting, the plugin supports optional digits, fallback patterns when a field does not match, and the ability to change or remove a mask after it has been applied. It works with HTML data attributes, so a developer can configure masks directly in the HTML markup without writing additional JavaScript. The library is compatible with React, Angular, Vue, and Zepto in addition to standard jQuery setups. At around 2 kilobytes when compressed, it is designed to add minimal weight to a page. It has been tested across a wide range of browsers including older versions of Internet Explorer, Chrome, Firefox, Safari, Opera, and Android browsers. Installation is available through npm, Bower, Composer, and Meteor. A CDN link is also available for use without a package manager. Full documentation and live demos are hosted on the project's GitHub Pages site.

Copy-paste prompts

Prompt 1
Using jquery-mask-plugin, help me add a US phone number mask formatted as (555) 123-4567 to my HTML form input field.
Prompt 2
Show me how to apply a credit card mask with jquery-mask-plugin that groups digits into sets of four separated by spaces.
Prompt 3
Help me create a currency input mask with jquery-mask-plugin where the decimal point stays fixed and digits shift left as the user types.
Prompt 4
Show me how to configure jquery-mask-plugin entirely with HTML data attributes so I don't need any extra JavaScript calls.
Open on GitHub → Explain another repo

← igorescobar on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.