Last active
November 3, 2022 13:40
-
-
Save LeoLopesWeb/06c62ee959d8aded9f91afb22691537a to your computer and use it in GitHub Desktop.
This file contains 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
<!-- 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 --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment