fix: update CPF and CNPJ document formatting and parsing logic in demo sdk
This commit is contained in:
+6
-5
@@ -1037,6 +1037,7 @@
|
|||||||
if (rawName.includes(':')) {
|
if (rawName.includes(':')) {
|
||||||
const parts = rawName.split(':');
|
const parts = rawName.split(':');
|
||||||
displayName = parts[0].trim();
|
displayName = parts[0].trim();
|
||||||
|
if (!docNum && parts[1]) {
|
||||||
docNum = parts[1].trim();
|
docNum = parts[1].trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1044,14 +1045,14 @@
|
|||||||
const digits = docNum ? String(docNum).replace(/\D/g, '') : '';
|
const digits = docNum ? String(docNum).replace(/\D/g, '') : '';
|
||||||
let docFormatted = '';
|
let docFormatted = '';
|
||||||
if (digits.length === 14) {
|
if (digits.length === 14) {
|
||||||
docFormatted = `CNPJ ${digits.replace(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/, '../-')}`;
|
docFormatted = 'CNPJ ' + digits.substring(0, 2) + '.' + digits.substring(2, 5) + '.' + digits.substring(5, 8) + '/' + digits.substring(8, 12) + '-' + digits.substring(12, 14);
|
||||||
} else if (digits.length === 11) {
|
} else if (digits.length === 11) {
|
||||||
docFormatted = `CPF ${digits.replace(/^(\d{3})(\d{3})(\d{3})(\d{2})$/, '..-')}`;
|
docFormatted = 'CPF ' + digits.substring(0, 3) + '.' + digits.substring(3, 6) + '.' + digits.substring(6, 9) + '-' + digits.substring(9, 11);
|
||||||
} else if (docNum) {
|
} else if (docNum) {
|
||||||
docFormatted = docNum;
|
docFormatted = docNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
const typeStr = `[${c.type || 'A1'}]`;
|
const typeStr = '[' + (c.type || 'A1') + ']';
|
||||||
const text = docFormatted ? `${displayName}, ${docFormatted} ${typeStr}` : `${displayName} ${typeStr}`;
|
const text = docFormatted ? `${displayName}, ${docFormatted} ${typeStr}` : `${displayName} ${typeStr}`;
|
||||||
opt.textContent = text;
|
opt.textContent = text;
|
||||||
certSelect.appendChild(opt);
|
certSelect.appendChild(opt);
|
||||||
@@ -1080,9 +1081,9 @@
|
|||||||
const digits = String(rawDoc).replace(/\D/g, '');
|
const digits = String(rawDoc).replace(/\D/g, '');
|
||||||
let docStr = '';
|
let docStr = '';
|
||||||
if (digits.length === 14) {
|
if (digits.length === 14) {
|
||||||
docStr = `CNPJ: ${digits.replace(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/, '../-')}`;
|
docStr = 'CNPJ: ' + digits.substring(0, 2) + '.' + digits.substring(2, 5) + '.' + digits.substring(5, 8) + '/' + digits.substring(8, 12) + '-' + digits.substring(12, 14);
|
||||||
} else if (digits.length === 11) {
|
} else if (digits.length === 11) {
|
||||||
docStr = `CPF: ${digits.replace(/^(\d{3})(\d{3})(\d{3})(\d{2})$/, '..-')}`;
|
docStr = 'CPF: ' + digits.substring(0, 3) + '.' + digits.substring(3, 6) + '.' + digits.substring(6, 9) + '-' + digits.substring(9, 11);
|
||||||
} else {
|
} else {
|
||||||
docStr = cert.type === 'A3' ? 'Token Físico A3' : 'ICP-Brasil';
|
docStr = cert.type === 'A3' ? 'Token Físico A3' : 'ICP-Brasil';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user