Correção o parametro de entrada do FormatarCep e Implementacao do formatarCnpj
This commit is contained in:
parent
5d307207d9
commit
f32cf62f0d
1 changed files with 23 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// Entrada: 12345000 Saída: 12.345-000
|
// Entrada: 12345000 Saída: 12.345-000
|
||||||
formatarCep(txt) {
|
formatarCep(txt) {
|
||||||
const soNumeros = e.target.value.replace(/[^\d]/g, '')
|
const soNumeros = `${txt}`.replace(/[^\d]/g, '')
|
||||||
if (!soNumeros) onChange(soNumeros);
|
if (!soNumeros) onChange(soNumeros);
|
||||||
|
|
||||||
let cep = '';
|
let cep = '';
|
||||||
|
@ -13,5 +13,27 @@ module.exports = {
|
||||||
cep += '-' + soNumeros.slice(5, 8);
|
cep += '-' + soNumeros.slice(5, 8);
|
||||||
|
|
||||||
return cep;
|
return cep;
|
||||||
|
},
|
||||||
|
// Entrada: 12345678000100 Saida: 12.345.678/0001-00
|
||||||
|
formatarCnpj(txt) {
|
||||||
|
const soNumeros = `${txt}`.replace(/[^\d]/g, '')
|
||||||
|
if (!soNumeros) onChange(soNumeros);
|
||||||
|
|
||||||
|
let cnpj = '';
|
||||||
|
cnpj += soNumeros.slice(0, 2)
|
||||||
|
|
||||||
|
if (soNumeros.length > 2)
|
||||||
|
cnpj += '.' + soNumeros.slice(2, 5)
|
||||||
|
|
||||||
|
if (soNumeros.length > 5)
|
||||||
|
cnpj += '.' + soNumeros.slice(5, 8)
|
||||||
|
|
||||||
|
if (soNumeros.length > 8)
|
||||||
|
cnpj += '/' + soNumeros.slice(8, 12)
|
||||||
|
|
||||||
|
if (soNumeros.length > 12)
|
||||||
|
cnpj += '-' + soNumeros.slice(12, 14)
|
||||||
|
|
||||||
|
return cnpj
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue