Created
March 20, 2018 21:27
-
-
Save antoniopresto/4d33d6523cd46527a6381e4336d2c930 to your computer and use it in GitHub Desktop.
mascara de celular
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
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