Created
November 19, 2012 11:27
-
-
Save deniscsz/4110213 to your computer and use it in GitHub Desktop.
Mascara de Tel com 9 dígitos
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
$('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