Skip to content

Instantly share code, notes, and snippets.

@deniscsz
Created November 19, 2012 11:27
Show Gist options
  • Save deniscsz/4110213 to your computer and use it in GitHub Desktop.
Save deniscsz/4110213 to your computer and use it in GitHub Desktop.
Mascara de Tel com 9 dígitos
$('input[name*="[telephone]"]').keydown( function(e){
if (e.keyCode >= 9){
length = this.value.length;
if (length == 0)
this.value += "(";
if (length == 3)
this.value += ")";
/*
Testa para ver se o ddd começa com 11 e coloca maxlength para 14
exemplo: (11) 12345-1234
*/
if(/(\(11\)).+/i.test(this.value)){
$(this).attr('maxlength','14');
if (length == 9)
this.value += "-";
} else {
$(this).attr('maxlength','13');
if (length == 8)
this.value += "-";
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment