
rodrigoKulb
(usa Ubuntu)
Enviado em 20/02/2013 - 21:22h
Para quem está procurando uma máscara para a celular com o DDD 11, depois de muito procurar consegui desenvolver uma!
<script>
// RODRIGO KULB
// 20/02/2013
// VIVA O LINUX
$(function(){
$('.maskCelular').mask("?99 9999-9999");
$('.maskCelular').keyup(function(){
var newValue = $(this).val().replace(/_/g,"");
var newValue = newValue.replace(/-/g,"");
if(newValue=='11 9')
{
$(this).unmask();
$(this).mask("?99 99999-9999");
$(this).val("11 9____-____");
$(this).setCursorPosition(4);
}
else if(newValue.length=='4')
{
$(this).unmask();
$(this).mask("?99 9999-9999");
$(this).val(newValue+"___-____");
$(this).setCursorPosition(4);
}
});
new function($) {
$.fn.setCursorPosition = function(pos) {
if ($(this).get(0).setSelectionRange) {
$(this).get(0).setSelectionRange(pos, pos);
} else if ($(this).get(0).createTextRange) {
var range = $(this).get(0).createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
}(jQuery);
});
</script>