Last active
August 17, 2016 17:02
-
-
Save viniciuscenci/8b0bda14c431410394b0df3343f0f113 to your computer and use it in GitHub Desktop.
jQuery MaskedInput plugin BR phone (9 digits) mask
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
//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