Skip to content

Instantly share code, notes, and snippets.

@ricardodantas
Created June 25, 2014 21:50
Show Gist options
  • Select an option

  • Save ricardodantas/8852e5e21191b5780cf8 to your computer and use it in GitHub Desktop.

Select an option

Save ricardodantas/8852e5e21191b5780cf8 to your computer and use it in GitHub Desktop.
Jquery Mask for brazilian pattern phone fields. From http://www.williamokano.com/2013/09/mascara-jquery-telefone-nono-9o-digito/
jQuery.fn.brTelMask = function() {
return this.each(function(){
var el = this;
$(el).focus(function(){
$(el).mask("(99) 9999-9999?9");
});
$(el).focusout(function(){
var phone, element;
element = $(el);
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");
}
});
});
}
$(document).ready(function() {
$(".campo-telefone").brTelMask();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment