What's this
It's a pure JavaScript mask input. Now you can use a simple and pure javascript lib to mask your input elements, without need to load jQuery or Zepto to do it.
Let's live a lightweight client-side world using micro libraries as VanillaMasker is! Don't worry about where this will work, because this is a cross-browser and cross-device library. And if you find any bug, please let us know about it reporting an issue.
If you wanna see how this lib works, click to test this demo page.
How to install
Download script
- development version (6.2 Kbytes);
- minified version (3.24 Kbytes);
- gzipped version (1.3 Kbytes);
We have the following CDN available, for development or minified versions:
//cdn.jsdelivr.net/vanilla-masker/1.1.0/vanilla-masker.js
//cdn.jsdelivr.net/vanilla-masker/1.1.0/vanilla-masker.min.js
We intent to automatically send new versions to the CDN, but keep in mind that the version you want might not be available there. Of course you can always download and put it in your own site.
NPM
For npm users you just run this command: npm install vanilla-masker --save
Bower
You can install it via bower too, using this command: bower install --save vanilla-masker
Meteor
And you can install inside your meteor projects with this command: meteor add bankfacil:vanilla-masker
How to use
Loading the lib
Like I said, you need to download and put this lib in your own site, using this tag below:
<!-- Loading the vanilla-masker lib -->
Common uses
Money format
// Masking input element to money.;// Masking input element to money with options.;// Masking an array of input elements to money.;// Converts number to money stringVMasker; // -> R$ 1.234,00
Only numbers
// Masking input element to number.;// Converts any string to numberVMasker; // -> 12334VMasker; // -> -12334
Custom pattern
// Listen the input element masking it to format with pattern.;// Converts value to masked phoneVMasker; // -> (10) 9991-1111// Converts value to masked dateVMasker; // -> 12/12/2000// Converts value to masked documentVMasker; // -> 999.111.111-01// Converts value to masked car plateVMasker; // -> ABC-1234// Converts value to masked vehicle identificationVMasker; // -> 9B.GR.D08X0.4.G.117974// Pass in an optional placeholder option to represent remaining characters to be enteredVMasker; // -> (4xx) xxx-xxxx
Undoing a mask
var el = document; // masking the input; // unmask!
Dynamic mask
Sometimes you need swap the mask according with value. You can see the sample below on codepen.io
{ var c = eventtarget; var v = cvalue; var m = cvaluelength > max ? 1 : 0; ; ; cvalue = VMasker;} var telMask = '(99) 9999-99999' '(99) 99999-9999';var tel = document;;tel; var docMask = '999.999.999-999' '99.999.999/9999-99';var doc = document;;doc;
Meteor uses
If your app is built on top of Meteor framework, you can use the lib in this way...
Welcome to Meteor!{{> myTemplate}}
You just need to bind the elements into the template rendered
function...
if MeteorisClientTemplatemyTemplate {;;;};
How to run localhost
- Install node.js - http://nodejs.org/download
- Clone this repository -
git clone git@github.com:vanilla-masker/vanilla-masker.git
- Install Grunt -
npm install -g grunt-cli
- Install Grunt dependencies -
cd vanilla-masker && npm install
- Running development mode -
grunt dev
- Open the browser - http://localhost:4500
Run test
- Run the command:
grunt test
Build project
- Run the command:
grunt build
TODO - we need pull requests :]
- Test Opera mini browser;
- Beautify Demo Page;
- Bind mask using
data-vm
attributes;
Compatibility
Desktop browsers:
- Chrome 4.0+
- Firefox 2.0+
- Safari 4.0+
- Opera 10.0+
- Internet Explorer 8+
Mobile browsers:
- Android browser 2.2+
- Chrome mobile 35.0+
- Firefox mobile 29.0+
- Opera mobile 10.0+
- iOS Safari 3.2+
- Windows Phone browsers
Contributors
Caio Ribeiro Pereira - caio.ribeiro.pereira@gmail.com Leandro Alvares da Costa - leandroadacosta@gmail.com Bobby - squidz.bee@gmail.com Henrique Antonini Silvério - contato@henriquesilverio.com Joilson Marques - joilsonmarques@gmail.com Leonardo Andrade - leonardopandrade@gmail.com Thiago Lagden - lagden@gmail.com
License
MIT License: http://bankfacil.mit-license.org