PiiCatalog.Validators (pii_catalog v0.1.0)

Copy Markdown View Source

Checks a candidate match must pass before it counts.

A regex finds values of the right shape; many of those are order numbers, timestamps or version strings. Where an identifier carries a check digit or a structure the regex cannot express, it is confirmed here.

Each check takes only the matched bytes. It does not depend on the text around them, so a value gives the same answer wherever it is found.

valid?/2 takes the name of a check, which is a pattern's validator field, not the pattern's name; several patterns could share one check. PiiCatalog.valid?/2 takes a pattern name.

Three checks compare a date of birth with today's date (Date.utc_today/0): :pesel_pl, :isikukood_ee (a date after today is refused) and :rrn_be (the reading for people born from 2000 is tried only for a year that has begun). Their answer for a given value can change as time passes.

Summary

Functions

Whether a day, month and two-digit year can be a date of birth. Without the century, 29 February is accepted in every year divisible by four.

What a check confirms, in a few words: "Luhn check digit". nil, no check, is "Format only".

The decimal digits in a value, in order, with separators dropped.

The IBAN length for a country code, or nil outside SEPA.

The IBAN length of every country in the EPC's list of SEPA countries, as a map from the country code to the length: %{"AD" => 24, ...}.

The ISO 7064 MOD 11,10 check digit for a list of digits. Used by the German Steuer-ID and the German and Croatian VAT numbers.

The Luhn check (ISO/IEC 7812-1), on a list of digits. Used by payment cards, and by Swedish personnummer on the ten-digit form.

A weighted mod-11 check digit: 11 minus the weighted sum mod 11, where 11 gives 0 and 10 gives nil, a number that is never issued. Used by the Norwegian fødselsnummer.

The name of every check valid?/2 runs.

Runs the named check on a matched value. nil accepts every value.

Functions

date?(year, month, day)

@spec date?(integer(), integer(), integer()) :: boolean()

Whether a day, month and two-digit year can be a date of birth. Without the century, 29 February is accepted in every year divisible by four.

describe(atom)

@spec describe(atom() | nil) :: String.t()

What a check confirms, in a few words: "Luhn check digit". nil, no check, is "Format only".

digits(value)

@spec digits(binary()) :: [0..9]

The decimal digits in a value, in order, with separators dropped.

iban_length(country)

@spec iban_length(String.t()) :: pos_integer() | nil

The IBAN length for a country code, or nil outside SEPA.

iban_lengths()

@spec iban_lengths() :: %{required(String.t()) => pos_integer()}

The IBAN length of every country in the EPC's list of SEPA countries, as a map from the country code to the length: %{"AD" => 24, ...}.

iso7064_mod11_10(digits)

@spec iso7064_mod11_10([0..9]) :: 0..9

The ISO 7064 MOD 11,10 check digit for a list of digits. Used by the German Steuer-ID and the German and Croatian VAT numbers.

luhn?(digits)

@spec luhn?([0..9]) :: boolean()

The Luhn check (ISO/IEC 7812-1), on a list of digits. Used by payment cards, and by Swedish personnummer on the ten-digit form.

mod11_check_digit(digits, weights)

@spec mod11_check_digit([0..9], [pos_integer()]) :: 0..9 | nil

A weighted mod-11 check digit: 11 minus the weighted sum mod 11, where 11 gives 0 and 10 gives nil, a number that is never issued. Used by the Norwegian fødselsnummer.

names()

@spec names() :: [atom(), ...]

The name of every check valid?/2 runs.

valid?(name, value)

@spec valid?(atom() | nil, binary()) :: boolean()

Runs the named check on a matched value. nil accepts every value.

The names are those in names/0; any other raises ArgumentError. Separators the pattern allows are dropped by the check itself, so "4111 1111 1111 1111" and "4111111111111111" give the same answer. For a binary value it returns a boolean and does not raise.