diff --git a/src/dk/cvr.spec.ts b/src/dk/cvr.spec.ts index 541bcd62..a20e519c 100644 --- a/src/dk/cvr.spec.ts +++ b/src/dk/cvr.spec.ts @@ -1,5 +1,5 @@ import { validate, format } from './cvr'; -import { InvalidLength, InvalidChecksum } from '../exceptions'; +import { InvalidLength, InvalidChecksum, InvalidFormat } from '../exceptions'; describe('dk/cvr', () => { it('format:DK 13585628', () => { @@ -31,4 +31,19 @@ describe('dk/cvr', () => { expect(result.error).toBeInstanceOf(InvalidChecksum); }); + + // No CVR number starts with 0. These all pass the modulus 11 check, so the + // leading digit is the only thing that rejects them. + test.each(['00000000', 'DK00000000', '01000004'])('validate:%s', value => { + const result = validate(value); + + expect(result.error).toBeInstanceOf(InvalidFormat); + }); + + // A registered CVR number still passes. + test.each(['24256790', 'DK24256790'])('validate:%s', value => { + const result = validate(value); + + expect(result.isValid && result.compact).toEqual('24256790'); + }); }); diff --git a/src/dk/cvr.ts b/src/dk/cvr.ts index b8e69ca2..cfbe064d 100644 --- a/src/dk/cvr.ts +++ b/src/dk/cvr.ts @@ -54,7 +54,7 @@ const impl: Validator = { if (value.length !== 8) { return { isValid: false, error: new exceptions.InvalidLength() }; } - if (!strings.isdigits(value)) { + if (!strings.isdigits(value) || value[0] === '0') { return { isValid: false, error: new exceptions.InvalidFormat() }; }