Skip to content

Instantly share code, notes, and snippets.

@antoniopresto
Created March 20, 2018 21:27
Show Gist options
  • Save antoniopresto/4d33d6523cd46527a6381e4336d2c930 to your computer and use it in GitHub Desktop.
Save antoniopresto/4d33d6523cd46527a6381e4336d2c930 to your computer and use it in GitHub Desktop.
mascara de celular
const value = num
.replace(/[^\d]/gm, '')
.replace(/^(\d\d)([^ ]+)$/, '($1) $2')
.replace(/(\(\d\d\)) (\d{5})(\d)$/, '$1 $2-$3')
.replace(/(\(\d\d\)) (\d{4})(\d{1,5})$/, '$1 $2-$3')
.replace(/(\(\d\d\)) (\d{4})-(\d)(\d{4})$/, '$1 $2$3-$4')
.replace(/(\(\d\d\)) (\d{5})(\d{4})(.*)/, '$1 $2-$3')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment