Last active
December 18, 2015 03:59
-
-
Save HenriqueSilverio/5721927 to your computer and use it in GitHub Desktop.
Máscara para inputs que aceita o número 9 extra quando necessário.
This file contains 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
/* | |
Masked input phone | |
Dependências: | |
- jQuery: http://jquery.com/ | |
- Masked input: http://digitalbush.com/projects/masked-input-plugin/ | |
*/ | |
$(function() { | |
$('#fone').mask("(99) 9999-9999?9").keydown(function() { | |
var $elem = $(this); | |
var tamanhoAnterior = this.value.replace(/\D/g, '').length; | |
setTimeout(function() { | |
var novoTamanho = $elem.val().replace(/\D/g, '').length; | |
if (novoTamanho !== tamanhoAnterior) { | |
if (novoTamanho === 11) { | |
$elem.unmask(); | |
$elem.mask("(99) 99999-9999"); | |
} else if (novoTamanho === 10) { | |
$elem.unmask(); | |
$elem.mask("(99) 9999-9999?9"); | |
} | |
} | |
}, 1); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment