Mascara telefone

4 respostas
M

alguem sabe me dizer pq esse javascript nao funciona no chrome no mozila e ie blz

function Ajusta_Telefone(input, evnt){
	if (input.value.length == 0) {
		if(clientNavigator == "IE") {
            if(evnt.keyCode != 48) {
                input.value += "(";
			}
		} else {
			if(evnt.keyCode == 0 && evnt.charCode != 48) {
				input.value += "(";
			}
		}
	}
	if (input.value.length == 3 && input.value.slice(0, 1) != '0') {
		if(clientNavigator == "IE") {
			input.value += ")";
		} else {
			if(evnt.keyCode == 0) {
				input.value += ")";
			}
		}
	}
	if (input.value.length == 8 && input.value.slice(0, 1) != '0') {
		if(clientNavigator == "IE") {
			input.value += "-";
		} else {
			if(evnt.keyCode == 0) {
				input.value += "-";
			}
		}
	}
	if ((input.value.length == 4 || input.value.length == 8) && input.value.slice(0, 1) == '0') {
		if(clientNavigator == "IE") {
			input.value += " ";
		} else {
			if(evnt.keyCode == 0) {
				input.value += " ";
			}
		}
	}
	return Bloqueia_Caracteres(evnt);
}

4 Respostas

LucasAdri07
Acho que seria pelo
clienteNavigator = "IE"

Eu gosto de utilizar essa máscara para telefone.

function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

E um exemplo de uso dela:

<td>Telefone:<input  name="txtTelefone" type="text" onkeypress="mascara(this,telefone)" size="14" maxlength="14" /></td>
M

legal mesmo essa ja usei… mas o fato é q não qria repassar todo meu sistema mudando pq ja esta pronto =(

LucasAdri07

Não testei aqui, mas sua mascara só funciona no IE? No FF e no Chrome não?

M

no ie e no firefox tmb somento no chrome não

Criado 18 de maio de 2012
Ultima resposta 18 de mai. de 2012
Respostas 4
Participantes 2