Skip to content

Commit 175f9ec

Browse files
committed
validation: add norwegian bank account number
1 parent 35cda14 commit 175f9ec

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

packages/validation/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,19 @@ import { validateObosMembershipNumber } from '@obosbbl/validation/se';
157157
validateObosMembershipNumber('0000000') // => true
158158
```
159159

160+
### validateBankAccountNumber()
161+
162+
Validates that the value is a valid organization number. Validates the checksum of the number.
163+
164+
```js
165+
// 🇳🇴 example
166+
import { validateBankAccountNumber } from '@obosbbl/validation/no';
167+
validateBankAccountNumber('12345678903'); // => true
168+
169+
// 🇸🇪 example
170+
// TODO: implement
171+
```
172+
160173

161174
## Example usage with Zod
162175

packages/validation/src/no.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,9 @@ export function validateNationalIdentityNumber(
159159

160160
return isValidDate(year, month, day);
161161
}
162+
163+
export function validateBankAccountNumber(value: string): boolean {
164+
// Norwegian bank account numbers use mod 11 with one control digits.
165+
// The first one is calculated for all 11 digits
166+
return mod11(value, [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]);
167+
}

packages/validation/src/validation.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ describe('no', () => {
4747
expect(no.validateOrganizationNumber(input, options)).toBe(expected);
4848
});
4949

50+
test.each([
51+
['12345678903', true],
52+
['12345678901', false],
53+
['9523 08 20059', false],
54+
['95230820052', false],
55+
['9523.08.20059', false],
56+
])('validateAccountNumber(%s) -> %s', (input, expected) => {
57+
expect(no.validateBankAccountNumber(input)).toBe(expected);
58+
});
59+
5060
test.each([
5161
['1234567', true, undefined],
5262
// too short

0 commit comments

Comments
 (0)