Contact Form Maker Masks
-
Hi guys,
I need some help please.
I would like to insert a single line text field to work as a phone number field.
I know that the contact form maker has a standard phone number field but this one doesnt work for me.
So, i would like to know how can i apply a phone number mask in this field as like a jquery or javascript do.
I found a javascript that do what i want, but i dont know how to include in this field:
===== Javascript code ====
function maskIt(w,m,r,a,p){
// Variáveis da fun??o
if (p===true) {
var txt = (!r) ? w.value.replace(/[^\w]+/gi,”) : w.value.replace(/[^\w]+/gi,”).reverse();
} else {
var txt = (!r) ? w.value.replace(/[^\d]+/gi,”) : w.value.replace(/[^\d]+/gi,”).reverse();
}
var mask = (!r) ? m : m.reverse();
var pre = (a ) ? a.pre : “”;
var pos = (a ) ? a.pos : “”;
var ret = “”;// Loop na máscara para aplicar os caracteres
for(var x=0,y=0, z=mask.length;x<z && y<txt.length;){
if((mask.charAt(x)!=’#’) && (mask.charAt(x)!=’&’)){
ret += mask.charAt(x); x++;
} else{
if(mask.charAt(x)==’#’){
ret += txt.charAt(y).replace(/[^\d]+/gi,”); y++; x++;
} else if(mask.charAt(x)==’&’) {
ret += txt.charAt(y).replace(/[\d]+/gi,”); y++; x++;
}
}
}// Retorno da fun??o
ret = (!r) ? ret : ret.reverse()
w.value = pre+ret+pos;
}// Novo método para o objeto ‘String’
String.prototype.reverse = function(){
return this.split(”).reverse().join(”);
};
function maskCel (obj) {
var str = obj.value;
var ddd = str.substring(1,3);
var pdi = str.substring(5,6);
// ORIGINAL – Mudei tirando o DDD if ((ddd == 11) && (pdi == 9)) {
if (pdi == 9) {
maskIt(obj,'(##) #.####-####’, false, “”, true);
} else {
maskIt(obj,'(##) ####-####’, false, “”, true);
}
}============== HTML code to call JS ===
<input type=”text” name=”placa” onkeyup=”maskCel(this)” />
================
To see how it works just copy and paste the code in this website:
https://codepen.io/pen/thank you for your help.
The page I need help with: [log in to see the link]
- The topic ‘Contact Form Maker Masks’ is closed to new replies.