Guest User

Untitled

a guest
Oct 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. /* Máscaras ER */
  2. function mascara(o,f){
  3. v_obj=o
  4. v_fun=f
  5. setTimeout("execmascara()",1)
  6. }
  7. function execmascara(){
  8. v_obj.value=v_fun(v_obj.value)
  9. }
  10. function mtel(v){
  11. v=v.replace(/\D/g,""); //Remove tudo o que não é dígito
  12. v=v.replace(/^(\d{2})(\d)/g,"($1) $2"); //Coloca parênteses em volta dos dois primeiros dígitos
  13. v=v.replace(/(\d)(\d{4})$/,"$1-$2"); //Coloca hífen entre o quarto e o quinto dígitos
  14. return v;
  15. }
  16. function mCNPJ(v){
  17. v=v.replace(/\D/g,"");
  18. v=v.replace(/^(\d{2})(\d)/,"$1.$2");
  19. v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3");
  20. v=v.replace(/\.(\d{3})(\d)/,".$1/$2");
  21. v=v.replace(/(\d{4})(\d)/,"$1-$2");
  22. return v;
  23. }
  24. function mcpf(v) {
  25. v=v.replace(/\D/g,"");
  26. v=v.replace(/(\d{3})(\d)/,"$1.$2");
  27. v=v.replace(/(\d{3})(\d)/,"$1.$2");
  28. v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2");
  29. return v;
  30. }
  31. function mCEP(v){
  32. v=v.replace(/\D/g,"");
  33. v=v.replace(/^(\d{2})(\d)/,"$1.$2");
  34. v=v.replace(/\.(\d{3})(\d)/,".$1-$2");
  35. return v;
  36. }
  37. function mNum(v){
  38. v=v.replace(/\D/g,"");
  39. return v;
  40. }
  41. function id( el ){
  42. return document.getElementById( el );
  43. }
  44. window.onload = function(){
  45. if (id('acf-field_59dd151f7f5c3')) {
  46. id('acf-field_59dd151f7f5c3').onkeypress = function(){
  47. mascara( this, mtel );
  48. }
  49. }
  50.  
  51. if (id('acf-field_59dd15337f5c4')) {
  52. id('acf-field_59dd15337f5c4').onkeypress = function(){
  53. mascara( this, mtel );
  54. }
  55. }
  56.  
  57. if (id('telefone')) {
  58. id('telefone').onkeypress = function(){
  59. mascara( this, mtel );
  60. }
  61. }
  62.  
  63. if (id('celular')) {
  64. id('celular').onkeypress = function(){
  65. mascara( this, mtel );
  66. }
  67. }
  68. if (id('cpf')) {
  69. id('cpf').onkeypress = function(){
  70. mascara( this, mcpf );
  71. }
  72. }
  73. if (id('cep')) {
  74. id('cep').onkeypress = function(){
  75. mascara( this, mcep );
  76. }
  77. }
  78. if (id('cnpj')) {
  79. id('cnpj').onkeypress = function(){
  80. mascara( this, mcnpj );
  81. }
  82. }
  83. }
Add Comment
Please, Sign In to add comment