JavaScript Input Mask
Note: IE9 is not supported in this module.
Getting started
First, install it.
npm i vanilla-text-mask --save
Then, use it as follows:
<script
type="text/javascript"
src="./node_modules/vanilla-text-mask/dist/vanillaTextMask.js"></script>
<script type="text/javascript">
var phoneMask = '(111) 111-1111'
var myInput = document.querySelector('.myInput')
textMask.maskInput({
inputElement: myInput,
mask: phoneMask
})
</script>
Documentation
As you can see in the code above, you are passing an object to vanillaTextMask.maskInput(...)
.
The object takes element
, which is the <input/>
element that you are masking. It also
accepts other values which are
documented here.
Example
To see an example of the code running, follow these steps:
- Clone the repo,
git clone git@github.com:msafi/text-mask.git
cd text-mask
npm install
npm run vanilla:dev
- Open http://localhost:3000
The code of the example is in vanilla/example
.
Contributing
We would love some contributions! Check out this document to get started.
License
Public domain - CC0 1.0 Universal