Created
July 31, 2012 00:31
-
-
Save pedroelsner/3212276 to your computer and use it in GitHub Desktop.
Masked Input Celular
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
// jQuery Masked Input | |
$('#celular').mask("(99) 9999-9999?9").ready(function(event) { | |
var target, phone, element; | |
target = (event.currentTarget) ? event.currentTarget : event.srcElement; | |
phone = target.value.replace(/\D/g, ''); | |
element = $(target); | |
element.unmask(); | |
if(phone.length > 10) { | |
element.mask("(99) 99999-999?9"); | |
} else { | |
element.mask("(99) 9999-9999?9"); | |
} | |
}); | |
/* | |
Quem encontrar problemas com o "target", utilize esta alternativa | |
Enviado por: Irineu <[email protected]> | |
*/ | |
$('#celular').focusout(function(){ | |
var phone, element; | |
element = $(this); | |
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"); | |
} | |
}).trigger('focusout'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oi, Pedro.
Se você mudar a segunda linha para:
$('#celular').mask("(99) 9999-9999?9").on('change',function(event) {
vai funcionar que é uma beleza na nova versão 1.10 do jquery e o novo maskedinput.
=)