1. vue-text-mask
Vue component for input masking
vue-text-mask
Package: vue-text-mask
Created by: text-mask
Last modified: Tue, 28 Jun 2022 20:32:23 GMT
Version: 6.1.2
License: Unlicense
Downloads: 50,181
Repository: https://github.com/text-mask/text-mask

Install

npm install vue-text-mask
yarn add vue-text-mask

Vue Input Mask

Getting started

First, install it.

 npm i vue-text-mask --save

Then, use it as follows:

 <template>
  <div>
    <label>Phone Number</label>
    <masked-input
      type="text"
      name="phone"
      class="form-control"
      v-model="phone"
      :mask="['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]"
      :guide="false"
      placeholderChar="#">
    </masked-input>
  </div>
</template>

<script>
  import MaskedInput from 'vue-text-mask'

  export default {
    name: 'name',

    components: {
      MaskedInput
    },

    data () {
      return {
        phone: ''
      }
    }
  }
</script>

You could alternatively define the component globally:

 import Vue from 'vue'
import MaskedInput from 'vue-text-mask'

Vue.component('masked-input', MaskedInput);

<masked-input> is essentially a wrapped <input> element - so it supports all the regular input properties (type, placeholder, class, etc). It is compatible with v-model 2-way binding, and is reactive to changes to any of the text mask props.

Documentation

For more information about the props that you can pass to the component, see
the documentation here.

Example

To see an example of the code running, follow these steps:

  1. Clone the repo, git clone [email protected]:text-mask/text-mask.git
  2. npm install
  3. npm run vue:dev
  4. Open http://localhost:3000

Contributing

We would love some contributions! Check out
this document to get started.

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin