Created
January 7, 2016 13:00
-
-
Save knoonrx/a180f0b7e3039e42c621 to your computer and use it in GitHub Desktop.
Regex para formatar números de telefone 10 ou 11 caracteres (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
var numero = 2199999999; | |
var formatNumber; | |
formatNumber = numero.length === 11 ? numero.match(/(\d{2})(\d{5})(\d{4})/) : numero.match(/(\d{2})(\d{4})(\d{4})/); | |
var finalNumber = '('+ formatNumber[1]+') '+formatNumber[2]+' - '+formatNumber[3]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment