Skip to content

Instantly share code, notes, and snippets.

@knoonrx
Created January 7, 2016 13:00
Show Gist options
  • Save knoonrx/a180f0b7e3039e42c621 to your computer and use it in GitHub Desktop.
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)
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