
Today is the oficial release of the version 0.4.3 of my jQuery Mask Plugin. Since I have never written about it before on this blog, I’ll teach you guys how to use it and some other cool features about it.
Downloading the code
wget https://github.com/igorescobar/jQuery-Mask-Plugin/blob/master/jquery.mask.min.js
The only thing that you guys need to do is include the javascript file of the plugin between the head tag in your HTML document and it’s all set to use.
The syntax
The jQuery Mask Plugin syntax is pretty simple. First, you input your selector, followed by the .mask and then as a parameters you have to put the mask that you want the plugin to apply on the form field.
Example
$(document).ready(function(){
$('.date').mask('00/00/0000');
});
In this example the mask 00/00/0000 will be applied in all the input fields that have the “.date” class. At jQuery Mask Plugin you don’t have pre-established masks, you choose the mask as you wish. On the website project you can see the jQuery Mask Plugin running with some others examples like this:
$(document).ready(function(){
$('.date').mask('11/11/1111');
$('.time').mask('00:00:00');
$('.date_time').mask('99/99/9999 00:00:00');
$('.cep').mask('99999-999');
$('.phone').mask('9999-9999');
$('.phone_with_ddd').mask('(99) 9999-9999');
$('.phone_us').mask('(999) 999-9999');
$('.mixed').mask('AAA 000-S0S');
$('.cpf').mask('999.999.999-99', {reverse: true});
$('.money').mask('000.000.000.000.000,00', {reverse: true});
});
As you can see, it’s possible to define other data type on each digit of the mask. This mask for example:
$('.mixed').mask('AAA 000-S0S');
The user can type a sequence of three alpha numeric characters, followed by space, three numeric characters, a slash, one string character, other number character and finally one string character, cool isn’t it?
Again, you can define the mask as you wish and the data type of each digit of the mask as well.
Features
- Data type validation of each digit.
- Flexible masks.
- Live Events for Ajax applications.
- Automatic maxlength.
- Reverse mode masks.
- OnKeyPress and OnComplete callbacks.
More about jQuery Mask Plugin
- jQuery Mask Plugin on Github
- Demonstration
- jQuery Mask Plugin Beta Version
- All versions of jQuery Mask Plugin
Any problems, please, let me know.


