Created
October 23, 2022 22:04
-
-
Save guilhermeabell/c150fe73edc0cfa09186c407299899e5 to your computer and use it in GitHub Desktop.
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
export const cpfMask = (value) => { | |
return value | |
.toString() | |
.replace(/\D/g, '') | |
.replace(/(\d{3})(\d)/, '$1.$2') | |
.replace(/(\d{3})(\d)/, '$1.$2') | |
.replace(/(\d{3})(\d{1,2})/, '$1-$2') | |
.replace(/(-\d{2})\d+?$/, '$1') | |
} | |
export const cnpjMask = (value) => { | |
return value | |
.toString() | |
.replace(/\D/g, '') | |
.replace(/(\d{2})(\d)/, '$1.$2') | |
.replace(/(\d{3})(\d)/, '$1.$2') | |
.replace(/(\d{3})(\d)/, '$1/$2') | |
.replace(/(\d{4})(\d)/, '$1-$2') | |
.replace(/(-\d{2})\d+?$/, '$1') | |
} | |
export const phoneMask = (value) => { | |
return value | |
.toString() | |
.replace(/\D/g, '') | |
.replace(/(\d{2})(\d)/, '($1) $2') | |
.replace(/(\d{4})(\d)/, '$1-$2') | |
.replace(/(\d{4})-(\d)(\d{4})/, '$1$2-$3') | |
.replace(/(-\d{4})\d+?$/, '$1') | |
} | |
export const cepMask = (value) => { | |
return value | |
.toString() | |
.replace(/\D/g, '') | |
.replace(/(\d{5})(\d)/, '$1-$2') | |
.replace(/(-\d{3})\d+?$/, '$1') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment