Vue mask
Input mask lib for Vue.js based on String-Mask
Installation
This version only works in Vue 2.
npm i di-vue-mask -S
Usage
import Vue from 'vue'
import VueMask from 'di-vue-mask'
Vue.use(VueMask);
Basic usage on HTML input element
<input type="text" name="mask" v-model="mask" v-mask="'0000-0000'">
For custom components without v-model
we can use v-mask-model
<my-input v-mask-model="mask" v-mask="'0000-0000'"></my-input>
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. |