Skip to content
This repository was archived by the owner on Dec 11, 2017. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion spec/Setup.Spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
feature("Masking an Input", function() {
feature("Masking an Input", function() {
scenario('Applying a mask to an already masked input',function(){
given("an input with two masks", function(){
input
Expand All @@ -14,5 +14,20 @@ feature("Masking an Input", function() {
expect(input).toHaveValue('1_');
});
});

scenario('Applying a mask and re-mapping rule',function(){
given("an input with re-mapping rules", function(){
input
.mask("99", {reMap:{'1':'9'}});
});

when("typing two numbers",function(){
input.mashKeys("18");
});

then("value should be correct",function(){
expect(input).toHaveValue('98');
});
});
});

11 changes: 9 additions & 2 deletions src/jquery.maskedinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ $.mask = {
},
autoclear: true,
dataName: "rawMaskFn",
placeholder: '_'
placeholder: '_',
reMap: {}
};

$.fn.extend({
Expand Down Expand Up @@ -78,7 +79,8 @@ $.fn.extend({
settings = $.extend({
autoclear: $.mask.autoclear,
placeholder: $.mask.placeholder, // Load default placeholder
completed: null
completed: null,
reMap: $.mask.reMap
}, settings);


Expand Down Expand Up @@ -238,6 +240,11 @@ $.fn.extend({
p = seekNext(pos.begin - 1);
if (p < len) {
c = String.fromCharCode(k);
/* a chance to remap inputs */
if(c in settings.reMap)
{
c = settings.reMap[c];
}
if (tests[p].test(c)) {
shiftR(p);

Expand Down