Skip to content

Instantly share code, notes, and snippets.

@viniciuscenci
Last active August 17, 2016 17:02
Show Gist options
  • Save viniciuscenci/8b0bda14c431410394b0df3343f0f113 to your computer and use it in GitHub Desktop.
Save viniciuscenci/8b0bda14c431410394b0df3343f0f113 to your computer and use it in GitHub Desktop.
jQuery MaskedInput plugin BR phone (9 digits) mask
//optimized
$(function(){
jQuery.fn.brTelMask = function () {
return this.each(function () {
var $el = $(this);
$el.mask("(99) 9999-9999?9");
$el.keyup(function () {
var phone = $el.val().replace(/\D/g, '');
if (phone.length > 10) {
$el.mask("(99) 99999-999?9");
} else if(phone.length > 9){
$el.mask("(99) 9999-9999?9");
}
});
});
};
$('.telefone').brTelMask();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment