Skip to content
personnummerPublic

About

Validate Swedish personal identity numbers

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

46 Commits

Folders and files

Repository files navigation

Personnummer

Validate Swedish personal identity numbers with Elixir.

Usage

Just validation

iex(1)> Personnummer.valid?("19900101-0017")
true

Validation and additional information

iex(1)> {:ok, pnr} = Personnummer.new("19900101-0017")
{:ok,
 %Personnummer{
   control: 7,
   coordination: false,
   date: ~D[1990-01-01],
   separator: "-",
   serial: 1
 }}
iex(2)> Personnummer.valid?(pnr)
true
iex(3)> gender = if Personnummer.is_female?(pnr) do "female" else "male" end
"male"
iex(4)> IO.puts "The person with personal identity number #{Personnummer.format(pnr)} is a #{gender} of age #{Personnummer.get_age(pnr)}"
The person with personal identity number 900101-0017 is a male of age 30
:ok

Installation

If available in Hex, the package can be installed by adding personnummer to your list of dependencies in mix.exs:

def deps do
  [
    {:personnummer, "~> 3.0.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/personnummer.

Testing

Use mix test to run doctests and unit tests.

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.

About

Validate Swedish personal identity numbers

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages