Giter Site home page Giter Site logo

jeanechabaudis / vue-masked-input Goto Github PK

View Code? Open in Web Editor NEW

This project forked from niksmr/vue-masked-input

0.0 2.0 0.0 1.46 MB

Masked input component for Vue.js

Home Page: https://niksmr.github.io/vue-masked-input/

License: MIT License

HTML 3.00% Vue 19.40% JavaScript 77.60%

vue-masked-input's Introduction

Vue Masked Input

Dead simple masked input component for Vue.js 2.X. Based on inputmask-core.

Install

npm

npm install vue-masked-input --save

Usage

Use it with v-model just like a native html input with the mask attribute:

<masked-input v-model="date" mask="11/11/1111" placeholder="dd/mm/yyyy" />

The following format characters define editable parts of the mask (see inputmask-core):

  • 1 - number
  • a - letter
  • A - letter, forced to upper case when entered
  • * - alphanumeric
  • # - alphanumeric, forced to upper case when entered
  • + - any character

Static characters

If you need to include one of these characters as a static part of the mask, you can escape them with a preceding backslash:

<masked-input v-model="phone" mask="\+\1 (111) 111-1111" placeholder="Phone number" type="tel" />

Raw input

You can also get a raw user input text if you want. Instead of using v-model you might need second argument of the input event:

<masked-input mask="\+\1 (111) 1111-11" placeholder="Phone" @input="rawVal = arguments[1]" />

Placeholder character

Placeholder character is customizable by placeholder-char attribute:

<masked-input v-model="phone" mask="\+\1 (111) 111-1111" placeholder-char="-" placeholder="Phone number" type="tel" />

Custom mask object

You can use your own mask options object, it will be passed to the inputmask-core constructor:

<masked-input
  v-model="custom"
  placeholder="Custom"
  :mask="{
    pattern: 'VVVV',
    formatCharacters: {
      'V': {
        validate: char => /[a-jA-J]/.test(char),
        transform: char => char.toUpperCase(),
      },
    },
  }"
/>

Known issues/TODO

  • Cut in mobile Chrome
  • Cyrillic chars are not supported in mobile Chrome
  • Backspace problems in mobile Chrome

Found more? It's open for feedback and pull requests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.