Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Máscaras comuns pt-br para jQuery MaskedInput
jQuery(function($) {
$('#cnpj,.cnpj').mask("99.999.999/9999-99");
$('#cep,.cep').mask("99.999-999");
$('#telefone-fixo,.telefone-fixo').mask("(99) 9999-9999");
$('#telefone-celular,.telefone-celular').mask("(99) 99999-9999");
// Se for um campo input do tipo date, mostrar máscara somente no Safari e Firefox pra evitar problemas com validação e mobile
var isFirefox = typeof InstallTrigger !== 'undefined';
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 || (function(p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || safari.pushNotification);
if (isFirefox || isSafari) {
$('#prazo,.prazo').mask("99/99/9999");
}
//Máscara de telefone fixo ou celular automático
$.mask.definitions['~'] = ['+-'];
$('#telefone-celular-fixo,.telefone-celular-fixo').focusout(function() {
var phone, element;
element = $(this);
element.unmask();
phone = element.val().replace(/\D/g, '');
if (phone.length > 10) {
element.mask('(99) 99999-999?9');
} else {
element.mask('(99) 9999-9999?9');
}
}).trigger('focusout');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.