Created
May 18, 2018 11:57
-
-
Save everaldomatias/dd6845ca280864344b4adcec98529f95 to your computer and use it in GitHub Desktop.
Máscara jQuery para CPF e CNPJ no mesmo campo
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
/* | |
Adiciona máscara em CPF e CNPJ no mesmo campo | |
Caso precise você pode mudar o seletor para usar um ID ou class. | |
Fonte: https://jsfiddle.net/pdd8g4mf/ | |
*/ | |
var CpfCnpjMaskBehavior = function (val) { | |
return val.replace(/\D/g, '').length <= 11 ? '000.000.000-009' : '00.000.000/0000-00'; | |
}, | |
cpfCnpjpOptions = { | |
onKeyPress: function(val, e, field, options) { | |
field.mask(CpfCnpjMaskBehavior.apply({}, arguments), options); | |
} | |
}; | |
$(function() { | |
$(':input[name=cpfCnpj]').mask(CpfCnpjMaskBehavior, cpfCnpjpOptions); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment