I taken from this thread decision Implement an input with a mask and adapted it for IE10, and added setter- and getter- functions.
BUT I TESTED FOR PHONE-mask ONLY
$(document).ready(function(){
var el_arr = document.querySelectorAll("[placeholder][data-slots]");
for (var el_ind=0; el_ind < el_arr.length; el_ind++ ){
var el = el_arr[el_ind];
var pattern = el.getAttribute("placeholder"),
slots = new Set(el.getAttribute("data-slots") || "_"),
prev = function(j){return Array.from(pattern, function(c,i){ return slots.has(c)? j=i+1: j;});}(0),
first = pattern.split('').findIndex(function(c){return slots.has(c);} ),
accept = new RegExp(el.getAttribute("data-accept") || "\\d", "g"),
clean = function(input){input = input.match(accept) || [];return Array.from(pattern, function(c){return input[0] === c || slots.has(c) ? input.shift() || c : c;});},
format = function(){
var elem = this;
var i_j_arr = [el.selectionStart, el.selectionEnd].map(function(i){
i = clean(el.value.slice(0, i)).findIndex(function(c){ return slots.has(c);});
return i<0? prev[prev.length-1]: elem.back? prev[i-1] || first: i;
});
el.value = clean(el.value).join('');
el.setSelectionRange(i_j_arr[0], i_j_arr[1]);
this.back = false;
},
// sdo added
get_masked_value = function(){
var input = this.value;
var ret=[];
for(var k in pattern){
if ( !input[k] )break;
if( slots.has(pattern[k]) && input[k]!=pattern[k]){
ret.push(input[k]);
}
}
return ret.join('');
},
set_masked_value = function(input){
var ret=[];
var index_in_value = 0;
for(var k in pattern){
if( slots.has(pattern[k]) && input[index_in_value]){
ret.push(input[index_in_value]);
index_in_value++;
}
else{
ret.push(pattern[k]);
}
}
this.value = ret.join('');
}
;
el.get_masked_value = get_masked_value;
el.set_masked_value = set_masked_value;
el.back = false;
el.addEventListener("keydown", function(event){ this.back = event.key === "Backspace";});
el.addEventListener("input", format);
el.addEventListener("focus", format);
el.addEventListener("blur", function() { return el.value === pattern && (el.value=""); });
}
});
+237 ---,---,---
. That white spaces are just a series of underscore(_
). If you country numbers are+1 777 888 990
just write+1 ___,___,___
(3 underscores joint). nishangsystem.com/nishang_stuff – Rotatory