Vue 2 Input Mask Plugin

1.2.1 · maintenance · verified Sun Apr 19

di-vue-mask is a Vue.js plugin that provides input masking capabilities for HTML input elements, specifically designed for Vue 2 applications. It is currently at version 1.2.1 and has not been updated in approximately 5 years. This library differentiates itself by building upon `String-Mask` for its core masking logic and offering a variety of predefined masks such as `v-mask-date`, `v-mask-phone`, `v-mask-decimal`, `v-mask-cpf`, `v-mask-cnpj`, `v-mask-cep`, and `v-mask-cc`, along with a generic `v-mask` directive. Its release cadence is inactive, with the last significant update in v1.1.0 focusing on compatibility. A key characteristic is its strict dependency on Vue 2, meaning it is not compatible with Vue 3 or later versions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install and register `di-vue-mask` as a Vue 2 plugin and apply a Brazilian phone number mask to an input field using `v-mask-phone.br`.

import Vue from 'vue';
import VueMask from 'di-vue-mask';

// Register the plugin globally
Vue.use(VueMask);

new Vue({
  el: '#app',
  data: {
    phoneNumber: ''
  },
  template: `
    <div id="app">
      <label for="phoneInput">Enter Phone Number (BR):</label>
      <input type="text" id="phoneInput" v-model="phoneNumber" v-mask-phone.br>
      <p>Raw value: {{ phoneNumber }}</p>
      <p>Try entering digits like '11987654321' to see the mask in action.</p>
    </div>
  `
});

view raw JSON →