Created
January 10, 2014 20:11
-
-
Save deniscsz/8361704 to your computer and use it in GitHub Desktop.
Código para Validação com Nono Dígito
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
$j('input[name*="telephone"]').keypress( 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. Para outros DDDs, alterar Regex. | |
exemplo: (11)95345-1234 que antes era assim (11)5345-1234 | |
*/ | |
if(/(\(11\)9(5[0-9]|6[0-9]|7[01234569]|8[0-9]|9[0-9])).+/i.test(this.value)){ | |
$j(this).attr('maxlength','14'); | |
if (length == 9) | |
this.value += "-"; | |
} else { | |
$j(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