Commit fbd3d720e7f6a7166350acfdaae1d8fc8280d723
1 parent
5d650d54
Exists in
master
and in
5 other branches
Phone mask #7
Showing
1 changed file
with
27 additions
and
75 deletions
Show diff stats
core/static/js/base/amadeus.js
| ... | ... | @@ -16,7 +16,7 @@ function campoNumerico(campo, evento){ |
| 16 | 16 | evento.returnValue = false; |
| 17 | 17 | return false; |
| 18 | 18 | } |
| 19 | -} | |
| 19 | +}; | |
| 20 | 20 | |
| 21 | 21 | function formatarCpf(campo, evento){ |
| 22 | 22 | var codTecla; |
| ... | ... | @@ -47,85 +47,37 @@ function formatarCpf(campo, evento){ |
| 47 | 47 | return false; |
| 48 | 48 | } |
| 49 | 49 | return false; |
| 50 | -} | |
| 50 | +}; | |
| 51 | 51 | |
| 52 | -function validarCpfSemAlert(campo,nome,idElementoMensagemErro){ | |
| 53 | - //alert("teste"); | |
| 54 | - cpf = campo.value; | |
| 55 | - | |
| 56 | - cpf = cpf.replace(".",""); | |
| 57 | - cpf = cpf.replace("-",""); | |
| 58 | - cpf = cpf.replace(".",""); | |
| 59 | - retorno = true; | |
| 52 | +function formatarTelefone(campo, evento){ | |
| 53 | + var codTecla; | |
| 54 | + var tamanho; | |
| 55 | + if( document.all ) { // Internet Explorer | |
| 56 | + codTecla = evento.keyCode; | |
| 57 | + } else if( document.layers ) { // Nestcape | |
| 58 | + codTecla = evento.which; | |
| 59 | + } else if( evento ) { // Firefox | |
| 60 | + codTecla = evento.which; | |
| 61 | + } | |
| 62 | + tamanho = campo.value.length; | |
| 60 | 63 | |
| 61 | - if(trim(cpf).length > 0){ | |
| 62 | - //alert("teste2"); | |
| 63 | - cpfstr= ''; | |
| 64 | - temp = cpf + ''; | |
| 65 | - | |
| 66 | - cpfstr = temp.substring(0,3); | |
| 67 | - cpfstr = cpfstr + temp.substring(3,6); | |
| 68 | - cpfstr = cpfstr + temp.substring(6,9); | |
| 69 | - cpfstr = cpfstr + temp.substring(9,11); | |
| 70 | - | |
| 71 | - | |
| 72 | - | |
| 73 | - retorno = false; | |
| 74 | - if(cpf != null){ | |
| 75 | - //alert("teste3"); | |
| 76 | - soma = 0; | |
| 77 | - digito1 = 0; | |
| 78 | - digito2 = 0; | |
| 79 | - for(i = 0; i < 9; i = i + 1) { | |
| 80 | - soma = soma + ((parseInt(cpf.substring(i,i+1)))*(11-(i+1))); | |
| 81 | - } | |
| 82 | - soma = soma % 11; | |
| 83 | - if (soma == 0 || soma == 1) { | |
| 84 | - digito1 = 0; | |
| 85 | - } else { | |
| 86 | - digito1 = 11 - soma; | |
| 87 | - } | |
| 88 | - soma = 0; | |
| 89 | - | |
| 90 | - for(i = 0; i < 9; i = i + 1) { | |
| 91 | - soma = soma + ((parseInt(cpf.substring(i,i+1)))*(12-(i+1))); | |
| 92 | - } | |
| 93 | - soma = soma + (digito1*2); | |
| 94 | - soma = soma % 11; | |
| 95 | - if (soma == 0 || soma == 1) { | |
| 96 | - digito2 = 0; | |
| 97 | - } | |
| 98 | - else{ | |
| 99 | - digito2 = 11 - soma; | |
| 100 | - } | |
| 101 | - digito = digito1 +''+ digito2; | |
| 102 | - | |
| 103 | - | |
| 104 | - //alert(cpfstr.substring(9,11)); | |
| 105 | - if(digito == (cpfstr.substring(9,11))){ | |
| 106 | - retorno = true; | |
| 107 | - } else{ | |
| 108 | - //alert("teste4"); | |
| 109 | - retorno = false; | |
| 110 | - | |
| 111 | - } | |
| 112 | - } else { | |
| 113 | - retorno = false; | |
| 64 | + if((codTecla > 47 && codTecla < 58) && tamanho < 14){ | |
| 65 | + | |
| 66 | + if(tamanho == 0){ | |
| 67 | + campo.value = "(" + campo.value; | |
| 68 | + }else if( tamanho == 3 ){ | |
| 69 | + campo.value = campo.value + ")"; | |
| 70 | + }else if(tamanho == 9){ | |
| 71 | + campo.value = campo.value + "-"; | |
| 114 | 72 | } |
| 115 | - }else{ | |
| 116 | - retorno = false; | |
| 117 | - } | |
| 118 | - //alert(retorno); | |
| 119 | - if(retorno == false){ | |
| 120 | - //alert('E-mail informado invalido! Por favor, especifique um E-mail válido para o campo \"' + nome + '\".'); | |
| 121 | - document.getElementById(idElementoMensagemErro).style.display = ''; | |
| 122 | - campo.focus(); | |
| 123 | - return false; | |
| 124 | - }else{ | |
| 125 | - document.getElementById(idElementoMensagemErro).style.display = 'none'; | |
| 126 | 73 | return true; |
| 74 | + } else if(codTecla == 0 || codTecla == 8){ | |
| 75 | + return true; | |
| 76 | + } else { | |
| 77 | + evento.returnValue = false; | |
| 78 | + return false; | |
| 127 | 79 | } |
| 128 | - return retorno; | |
| 80 | + return false; | |
| 129 | 81 | } |
| 130 | 82 | |
| 131 | 83 | /* | ... | ... |