From fbd3d720e7f6a7166350acfdaae1d8fc8280d723 Mon Sep 17 00:00:00 2001 From: ailsoncgt Date: Wed, 5 Oct 2016 23:41:17 -0300 Subject: [PATCH] Phone mask #7 --- core/static/js/base/amadeus.js | 102 +++++++++++++++++++++++++++--------------------------------------------------------------------------- 1 file changed, 27 insertions(+), 75 deletions(-) diff --git a/core/static/js/base/amadeus.js b/core/static/js/base/amadeus.js index 731d026..85b3dbc 100644 --- a/core/static/js/base/amadeus.js +++ b/core/static/js/base/amadeus.js @@ -16,7 +16,7 @@ function campoNumerico(campo, evento){ evento.returnValue = false; return false; } -} +}; function formatarCpf(campo, evento){ var codTecla; @@ -47,85 +47,37 @@ function formatarCpf(campo, evento){ return false; } return false; -} +}; -function validarCpfSemAlert(campo,nome,idElementoMensagemErro){ - //alert("teste"); - cpf = campo.value; - - cpf = cpf.replace(".",""); - cpf = cpf.replace("-",""); - cpf = cpf.replace(".",""); - retorno = true; +function formatarTelefone(campo, evento){ + var codTecla; + var tamanho; + if( document.all ) { // Internet Explorer + codTecla = evento.keyCode; + } else if( document.layers ) { // Nestcape + codTecla = evento.which; + } else if( evento ) { // Firefox + codTecla = evento.which; + } + tamanho = campo.value.length; - if(trim(cpf).length > 0){ - //alert("teste2"); - cpfstr= ''; - temp = cpf + ''; - - cpfstr = temp.substring(0,3); - cpfstr = cpfstr + temp.substring(3,6); - cpfstr = cpfstr + temp.substring(6,9); - cpfstr = cpfstr + temp.substring(9,11); - - - - retorno = false; - if(cpf != null){ - //alert("teste3"); - soma = 0; - digito1 = 0; - digito2 = 0; - for(i = 0; i < 9; i = i + 1) { - soma = soma + ((parseInt(cpf.substring(i,i+1)))*(11-(i+1))); - } - soma = soma % 11; - if (soma == 0 || soma == 1) { - digito1 = 0; - } else { - digito1 = 11 - soma; - } - soma = 0; - - for(i = 0; i < 9; i = i + 1) { - soma = soma + ((parseInt(cpf.substring(i,i+1)))*(12-(i+1))); - } - soma = soma + (digito1*2); - soma = soma % 11; - if (soma == 0 || soma == 1) { - digito2 = 0; - } - else{ - digito2 = 11 - soma; - } - digito = digito1 +''+ digito2; - - - //alert(cpfstr.substring(9,11)); - if(digito == (cpfstr.substring(9,11))){ - retorno = true; - } else{ - //alert("teste4"); - retorno = false; - - } - } else { - retorno = false; + if((codTecla > 47 && codTecla < 58) && tamanho < 14){ + + if(tamanho == 0){ + campo.value = "(" + campo.value; + }else if( tamanho == 3 ){ + campo.value = campo.value + ")"; + }else if(tamanho == 9){ + campo.value = campo.value + "-"; } - }else{ - retorno = false; - } - //alert(retorno); - if(retorno == false){ - //alert('E-mail informado invalido! Por favor, especifique um E-mail vĂ¡lido para o campo \"' + nome + '\".'); - document.getElementById(idElementoMensagemErro).style.display = ''; - campo.focus(); - return false; - }else{ - document.getElementById(idElementoMensagemErro).style.display = 'none'; return true; + } else if(codTecla == 0 || codTecla == 8){ + return true; + } else { + evento.returnValue = false; + return false; } - return retorno; + return false; } /* -- libgit2 0.21.2