personnummer_erl

CI License

Validate, parse and format Swedish personal identity numbers (personnummer) in Erlang/OTP. Implements the personnummer specification v3.1.

Supports:

Installation

Add to rebar.config:

{deps, [{personnummer_erl, "3.1.2"}]}.

Requires Erlang/OTP 27 or newer.

Quick start

{ok, Pnr} = personnummer:parse(<<"198608134667">>),

true = personnummer:valid(<<"198608134667">>),
<<"860813-4667">> = personnummer:format(Pnr),
<<"198608134667">> = personnummer:format(Pnr, true),
{1986, 8, 13} = personnummer:get_date(Pnr),
19 = personnummer:get_century(Pnr),
<<"466">> = personnummer:get_serial(Pnr),
7 = personnummer:get_check(Pnr),
<<"-">> = personnummer:get_separator(Pnr),
true = personnummer:is_female(Pnr),
false = personnummer:is_coordination_number(Pnr),
false = personnummer:is_interim_number(Pnr).

Options

%% Reject coordination numbers (samordningsnummer).
personnummer:parse(Input, #{allow_coordination_number => false}).

%% Accept interim numbers (T-numbers). Disabled by default.
personnummer:parse(<<"20000101T220">>, #{allow_interim_number => true}).

Defaults: allow_coordination_number => true, allow_interim_number => false.

Compliance

The test suite is driven by JSON fixtures vendored from personnummer/meta. See test/testdata/README.md for refresh instructions.

Development

This project uses Mise for tool versions and task running. Erlang/OTP, rebar3, and ELP are pinned in mise.toml. Eqwalizer tasks resolve ELP through Mise and unset ELP_EQWALIZER_PATH so custom PATH entries or unrelated local checker builds cannot override the pinned toolchain.

$ mise install
$ mise compile
$ mise test
$ mise format     # apply erlfmt
$ mise check      # compile, fmt-check, eunit, dialyzer, eqwalizer
$ mise eq-all     # eqwalizer (installed by Mise)
$ mise cover      # test coverage report
$ mise docs       # ex_doc

CI runs compilation, formatting checks, EUnit with coverage, Dialyzer, and Eqwalizer on OTP 27, 28, and 29.

Conventions

Releasing

  1. Bump vsn in src/personnummer_erl.app.src and convert the [Unreleased] heading in CHANGELOG.md to the new version. Commit and push.
  2. Run mise check to confirm everything is green.
  3. Run mise publish. This publishes to Hex (requires rebar3 hex user auth once), tags vX.Y.Z, and pushes the tag.

In memoriam

Fredrik "Frozzare" Forsmo (1991-2026) was the initiator, co-founder and a core contributor of the personnummer project. This library carries his work. He is missed.

License

MIT