Skip to content

Instantly share code, notes, and snippets.

@paulofreitas
Created October 11, 2013 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulofreitas/6941716 to your computer and use it in GitHub Desktop.
Save paulofreitas/6941716 to your computer and use it in GitHub Desktop.
Implementação do nono dígito com o Masked Input Plugin (http://digitalbush.com/projects/masked-input-plugin/).
var changePhoneMask = function () {
var phone = $(this).val().replace(/\D+/g, '');
if (phone.length == 2) {
if ($.inArray(phone, [11, 12, 13, 14, 15, 16, 17, 18, 19] > -1)) {
$(this).unmask().mask('(99) 99999-9999');
} else {
$(this).unmask().mask('(99) 9999-9999');
}
}
$(this).val(phone).caret(5, 5).triggerHandler('input'); // Firefox
$(this).triggerHandler('paste'); // IE
};
$(function () {
$('#phone').mask('(99) 9999-9999');
$('#mobile').mask('(99) 9999-9999');
$('#mobile').on('keyup', changePhoneMask);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment