Created
October 22, 2017 18:14
-
-
Save plowzzer/fce68fbfc957df09093c3c6a6ea2275d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Máscaras ER */ | |
function mascara(o,f){ | |
v_obj=o | |
v_fun=f | |
setTimeout("execmascara()",1) | |
} | |
function execmascara(){ | |
v_obj.value=v_fun(v_obj.value) | |
} | |
function mtel(v){ | |
v=v.replace(/\D/g,""); //Remove tudo o que não é dígito | |
v=v.replace(/^(\d{2})(\d)/g,"($1) $2"); //Coloca parênteses em volta dos dois primeiros dígitos | |
v=v.replace(/(\d)(\d{4})$/,"$1-$2"); //Coloca hífen entre o quarto e o quinto dígitos | |
return v; | |
} | |
function mCNPJ(v){ | |
v=v.replace(/\D/g,""); | |
v=v.replace(/^(\d{2})(\d)/,"$1.$2"); | |
v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3"); | |
v=v.replace(/\.(\d{3})(\d)/,".$1/$2"); | |
v=v.replace(/(\d{4})(\d)/,"$1-$2"); | |
return v; | |
} | |
function mcpf(v) { | |
v=v.replace(/\D/g,""); | |
v=v.replace(/(\d{3})(\d)/,"$1.$2"); | |
v=v.replace(/(\d{3})(\d)/,"$1.$2"); | |
v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2"); | |
return v; | |
} | |
function mCEP(v){ | |
v=v.replace(/\D/g,""); | |
v=v.replace(/^(\d{2})(\d)/,"$1.$2"); | |
v=v.replace(/\.(\d{3})(\d)/,".$1-$2"); | |
return v; | |
} | |
function mNum(v){ | |
v=v.replace(/\D/g,""); | |
return v; | |
} | |
function id( el ){ | |
return document.getElementById( el ); | |
} | |
window.onload = function(){ | |
if (id('acf-field_59dd151f7f5c3')) { | |
id('acf-field_59dd151f7f5c3').onkeypress = function(){ | |
mascara( this, mtel ); | |
} | |
} | |
if (id('acf-field_59dd15337f5c4')) { | |
id('acf-field_59dd15337f5c4').onkeypress = function(){ | |
mascara( this, mtel ); | |
} | |
} | |
if (id('telefone')) { | |
id('telefone').onkeypress = function(){ | |
mascara( this, mtel ); | |
} | |
} | |
if (id('celular')) { | |
id('celular').onkeypress = function(){ | |
mascara( this, mtel ); | |
} | |
} | |
if (id('cpf')) { | |
id('cpf').onkeypress = function(){ | |
mascara( this, mcpf ); | |
} | |
} | |
if (id('cep')) { | |
id('cep').onkeypress = function(){ | |
mascara( this, mcep ); | |
} | |
} | |
if (id('cnpj')) { | |
id('cnpj').onkeypress = function(){ | |
mascara( this, mcnpj ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment