Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/lib/isVAT.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ const AU = (str) => {
return (total !== 0 && total % 89 === 0);
};

const CO = (str) => {
// @see {@link https://es.wikipedia.org/wiki/N%C3%BAmero_de_Identificaci%C3%B3n_Tributaria_(Colombia)}
const hasValidCheckNumber = (digits) => {
const weights = [41, 37, 29, 23, 19, 17, 13, 7, 3];
const lastDigit = digits.pop(); // used as check number

const mod = digits.reduce((acc, el, idx) => acc + (el * weights[idx]), 0) % 11;

const calculatedCheckNumber = mod < 2 ? mod : 11 - mod;

return calculatedCheckNumber === lastDigit;
};

return /^(CO)?\d{10}$/.test(str) && hasValidCheckNumber((str.match(/\d/g).map(el => +el)));
};

const CH = (str) => {
// @see {@link https://www.ech.ch/de/ech/ech-0097/5.2.0}
const hasValidCheckNumber = (digits) => {
Expand Down Expand Up @@ -113,7 +129,7 @@ export const vatMatchers = {
BO: str => /^(BO)?\d{7}$/.test(str),
BR: str => /^(BR)?((\d{2}.\d{3}.\d{3}\/\d{4}-\d{2})|(\d{3}.\d{3}.\d{3}-\d{2}))$/.test(str),
CL: str => /^(CL)?\d{8}-\d{1}$/.test(str),
CO: str => /^(CO)?\d{10}$/.test(str),
CO,
CR: str => /^(CR)?\d{9,12}$/.test(str),
EC: str => /^(EC)?\d{13}$/.test(str),
SV: str => /^(SV)?\d{4}-\d{6}-\d{3}-\d{1}$/.test(str),
Expand Down
6 changes: 4 additions & 2 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15678,8 +15678,10 @@ describe('Validators', () => {
validator: 'isVAT',
args: ['CO'],
valid: [
'CO1234567890',
'1234567890',
'CO1234567896',
'1100000001',
'1234567896',
'8001972684', // e.g. DIAN NIT 800.197.268-4
],
invalid: [
'CO 1234567890',
Expand Down
Loading