LeoLopesWeb
11/20/2018 - 7:38 PM

jQuery Input mask plugin

<!-- pode ser necess√°rio adicionar antes do head -->
<!-- phone mask -->
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.min.js"></script>
  <script> 
    (function ($) {
      $(document).ready(function (e) {
        
        // mascara telefone fixo/celular
        var SPMaskBehavior = function (val) {
          return val.replace(/\D/g, "").length === 11 ? "(00) 00000-0000" : "(00) 0000-00009";
        },
        spOptions = {
          onKeyPress: function (val, e, field, options) {
            field.mask(SPMaskBehavior.apply({}, arguments), options);
          },
        };
    
        $("#form-field-telefone1").mask(SPMaskBehavior, spOptions);
    
        // mascara cpf/cnpj
        var options = {
          onKeyPress: function (cpf, ev, el, op) {
            var masks = ["000.000.000-000", "00.000.000/0000-00"];
            $("#cpf_cnpj").mask(cpf.length > 14 ? masks[1] : masks[0], op);
          },
        };
        $("#cpf_cnpj").length > 11 ? $("#cpf_cnpj").mask("00.000.000/0000-00", options) : $("#cpf_cnpj").mask("000.000.000-00#", options);

      });
    })(jQuery);
  </script>
  <!-- /phone mask -->