Created
September 22, 2020 14:32
-
-
Save tosipaulo/59365515782a82b2981ca26f84e45a33 to your computer and use it in GitHub Desktop.
Mask
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 class Mask { | |
static cpf_cnpj(value) { | |
return value | |
.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)(\.)(\d{2})(\d)(\.)(\d{2})(\d)(\-)(\d{3})/, '$1.$2$4.$5$7/$8$10') | |
.replace(/(\/\d{4})(\d{1,2})/, '$1-$2') | |
.replace(/(-\d{2})\d+?$/, '$1'); | |
} | |
static cep(value) { | |
return value | |
.replace(/\D/g, '') | |
.replace(/(\d{5})(\d)/, '$1-$2') | |
.replace(/(-\d{3})\d+?$/, '$1'); | |
} | |
static telefone(value) { | |
return value | |
.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)(\d{4})(\d)/, '$1-$2') | |
.replace(/(-\d{4})\d+?$/, '$1'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment