Skip to content

devindex/vue-mask

Repository files navigation

Vue mask

Input mask lib for Vue.js based on String-Mask

Installation

This version only works in Vue 3.

# npm
$ npm i -S @devindex/vue-mask

# yarn
$ yarn add @devindex/vue-mask

Usage

import { createApp } from 'vue';
import VueMask from '@devindex/vue-mask'; // <-- ADD THIS LINE
import App from './App.vue';

const app = createApp(App);

app.use(VueMask);  // <-- ADD THIS LINE

app.mount('#app');

Basic usage on HTML input element

<input type="text" name="mask" v-model="mask" v-mask="'0000-0000'">

Available masks

v-mask

<input type="text" name="mask" v-model="mask" v-mask="'0000-0000'">

v-mask-date (us|br)

<input type="text" name="date" v-model="maskDate" v-mask-date.br>

v-mask-phone (us|br)

<input type="text" name="phone" v-model="maskPhone" v-mask-phone.br>

v-mask-decimal (us|br)

<input type="text" name="decimal" v-model="maskDecimal" v-mask-decimal.br="2">

v-mask-number

<input type="text" name="number" v-model="maskNumber" v-mask-number>

v-mask-cpf

<input type="text" name="cpf" v-model="maskCpf" v-mask-cpf>

v-mask-cnpj

<input type="text" name="cnpj" v-model="maskCnpj" v-mask-cnpj>

v-mask-cep

<input type="text" name="cep" v-model="maskCep" v-mask-cep>

v-mask-cc

<input type="text" name="cc" v-model="maskCc" v-mask-cc>

Special mask characters

Character Description
0 Any numbers
9 Any numbers (Optional)
# Any numbers (Recursive)
A Any alphanumeric character
S Any letter
U Any letter (All lower case character will be mapped to uppercase)
L Any letter (All upper case character will be mapped to lowercase)
$ Escape character, used to escape any of the special formatting characters.