Skip to content

Commit

Permalink
Merge pull request #106 from koblas/no_fodselsnummer
Browse files Browse the repository at this point in the history
fix: bug in year validation
  • Loading branch information
koblas committed Sep 6, 2023
2 parents 0ee6f7e + 731e9b1 commit ce05f49
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"version": "1.10.0",
"description": "Standard Number Validation",
"files": [
"lib"
"README.md",
"LICENSE.txt",
"lib",
"src"
],
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
Expand Down
35 changes: 27 additions & 8 deletions src/no/fodselsnummer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,33 @@ describe('no/fodselsnummer', () => {
expect(result).toEqual('151086 95088');
});

test.each(['11111598403', '23114048690', '15108695088'])(
'validate:%s',
value => {
const result = validate(value);

expect(result.isValid).toEqual(true);
},
);
test.each([
'11111598403',
'23114048690',
'15108695088',
// from norsk-validator
'01010750160',
'30042099941',
'22052099424',
'09062099345',
'020161 26007',
])('validate:%s', value => {
const result = validate(value);

expect(result.isValid).toEqual(true);
});

test.each([
'45014054018',
// from norsk-validator
'11111234567',
'1234123456',
'',
])('validate:%s', value => {
const result = validate(value);

expect(result.isValid).toEqual(false);
});

it('validate:151086 95088', () => {
const result = validate('151086 95088');
Expand Down
2 changes: 1 addition & 1 deletion src/no/fodselsnummer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function checkBirthdate(value: string) {
yy += 1800;
} else if (rest < 1000 && yy < 40) {
yy += 2000;
} else if (rest < 1000 && yy >= 40) {
} else if (rest >= 900 && rest < 1000 && yy >= 40) {
yy += 1900;
} else {
return false;
Expand Down

0 comments on commit ce05f49

Please sign in to comment.