@thedoctor0/vue-input-mask

Input mask directive for Vue.js - lightweight, dependency free, written in TypeScript.
4,195 4
Install
npm install @thedoctor0/vue-input-mask
Latest Version:1.0.10
License:MIT
Last Updated:Mar 24, 2023
Links: GitHub  ·  npm
Maintainer: thedoctor0

Vue Input Mask

npm Github file size npm Build Status codecov Codacy Badge License

Input mask directive for Vue.js - lightweight, dependency free, written in TypeScript.

Install

NPM

npm i -S @thedoctor0/vue-input-mask

Yarn

yarn add @thedoctor0/vue-input-mask

Initialization

Global

import VueInputMask from '@thedoctor0/vue-input-mask';

Vue.directive(VueInputMask);

Local

import { mask } from '@thedoctor0/vue-input-mask';

export default {
  directives: { mask }
}

Usage

<input id="masked-input" type="text" v-mask="'###-###-####'" v-model="inputModelVariable">
<!-- OR -->
<input id="masked-input" type="text" v-mask="nameOfVariableWithMask" v-model="inputModelVariable">

Raw value

There are two ways to get the raw input value: from attribute, using demask helper.

Attribute

The directive adds input raw value parameter directly onto the element, so its easy to get it:

const rawValue = document.getElementById('masked-input').getAttribute('raw-value');
Demask

It is also possible to use helper function to get raw value from masked input value:

import { demask } from '@thedoctor0/vue-input-mask';

const rawValue = demask(this.inputModelVariable, '###-###-####');

Tokens

List of supported tokens available for use in mask:

Value Format
# Number (0-9)
S Letter in any case (a-z, A-Z)
N Number or letter (a-z, A-Z, 0-9)
X Any number, letter or symbol
a Letter that will be displayed in lower case (a-z)
A Letter that will be displayed in upper case (A-Z)
+ Skip one or more characters
! Escape next character in mask

Related Packages

@justfork/maska

Simple zero-dependency input mask for Vue.js and vanilla JS

4,780 2,021
vue-masked-input

Masked input component for Vue.js 2.X

449,387 451
vue-3-mask

A mask library for input fields in Vue.js 3

106,849
vue-input-mask

Masked input component for Vue

24,465 14
ionic-vue-input-mask

Uma biblioteca para adicionar máscaras a campos de entrada Vue.

500

Version History

Version Released License
1.0.10 MIT
1.0.9 MIT
1.0.8 MIT
1.0.7 MIT
1.0.6 MIT