CVR (CVR v0.1.0)
View SourceValidates and generates Danish CVR-numbers.
Every Danish company is registered in CVR ("Det Central
Virksomhedsregister"/"The Central Business Registry") with a unique
CVR-number. This library can validate a given CVR-number according to the
modulo-11 rule and generate random ones (if StreamData
is present).
The modulo-11 rule
Like Danish CPR-numbers, CVR-numbers are generated according to a modulo-11 rule. For CVR-numbers, the first 7 digits is a sequential counter and the eighth digit is a control digit. This means that not all 8-digit numbers are valid CVR-numbers. For instance, 24256790 is a valid CVR-number, because the sum of multiplying each digit with a predefined weight divides evenly with 11. Similarly 24256791 is not a valid CVR number because the modulo-11 test does not hold.
Summary
Functions
@spec generate() :: StreamData.t(pos_integer())
Generate a random CVR-number.
Requires StreamData
. The generated
CVR-numbers are guaranteed to be valid.
Validates whether a given CVR number is valid or not.
This function accepts both integers and strings as inputs. The strings must either contain a number, or a number preceeded by either "DK" or "DK-". The "DK-12345678" format is commonly used in systems that can handle different company registration IDs from different countries.
Usage
iex> CVR.valid?("DK24256790")
true
iex> CVR.valid?("DK-24256790")
true
iex> CVR.valid?(24256790)
true
iex> CVR.valid?("Not a number")
false
iex> CVR.valid?("DK-24256791")
false
iex> CVR.valid?(24256791)
false
iex> CVR.valid?(10000000)
false