Skip to content

Commit

Permalink
Merge pull request #120 from strotgen/main
Browse files Browse the repository at this point in the history
Fix NIF validation for Portugal.
  • Loading branch information
koblas committed Jul 12, 2024
2 parents 4ef3cee + 95ce430 commit ecace41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/pt/nif.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ describe('pt/nif', () => {

expect(result.error).toBeInstanceOf(InvalidChecksum);
});

it('validate:PT 507 104 560', () => {
const result = validate('507104560');

expect(result.isValid && result.compact).toEqual('507104560');
});

it('validate:PT 506 035 220', () => {
const result = validate('506035220');

expect(result.isValid && result.compact).toEqual('506035220');
});
});
2 changes: 1 addition & 1 deletion src/pt/nif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const impl: Validator = {
modulus: 11,
});

if (String((11 - sum) % 10) !== check) {
if (String((11 - sum) % 11 % 10) !== check) {
return { isValid: false, error: new exceptions.InvalidChecksum() };
}

Expand Down

0 comments on commit ecace41

Please sign in to comment.