The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Se::PersonNr - Module for validating and generating a Swedish personnummer.

SYNOPSIS

  use Se::PersonNr;
  my $pnr = new Se::PersonNr('511013-3815'); # faked, but valid
  print "It's fake! Checksum should be: " . $pnr->get_valid() unless ($pnr->is_valid());

DESCRIPTION

Se::PersonNr is a module that is used to validate a Swedish personnummer. A personnummer is a unique number generated by the government for each indivual in Sweden. They are also used as registration numbers for corporations and other business entities.

A personnummer consists of six digits representing date of birth follow by three serial number digits and a checksum digit. The date of birth and serial number is split by a plus or minus sign. (The minus sign is replaced by a plus sign when he or she turn 100.) The date part is two digits for the year followed by two for the month and another two for the day of month.

Example: A man born on the 13th of October 1951 with serial number 381 gets the personnummer 511013-3815.

The module will accept personnummer in the formats yymmdd-sssc, yymmddsssc, yyyymmdd-sssc and yyyymmddsssc but only return the first format. The first format may also use the plus sign.

More information about personnummer can be found at: http://www.rsv.se/pdf/70407.pdf (it's in Swedish).

METHODS

$pnr = Se::PersonNr->new($personnummer)

Create a new PersonNr object. Optionally you may pass the personummer in the constructor directly.

$personnummer = $pnr->personnr($newpersonnummer);

Returns the personummer in the object and sets a new one if supplied.

$year = $pnr->year($newyear);

Returns the year of birth for the person and sets a new one if supplied.

$month = $pnr->month($newmonth);

Returns the month of birth for the person and sets a new one if supplied.

$day = $pnr->day($newday);

Returns the day of birth for the person and sets a new one if supplied.

$serial = $pnr->serial($newserial);

Returns the serial number for the person and sets a new one if supplied.

$checksum = $pnr->checksum($newchecksum);

Returns the checksum digit for the person and sets a new one if supplied.

$validity = $pnr->is_valid();

Returns 1 if the checksum digit is valid. No other validation is made. Returns 0 if fake.

$correctchecksum = $pnr->get_valid($incomplete);

Returns the correct checksum digit for the incomplete personnummer supplied. The personnummer passed should have the format yymmddsss. If no incomplete personnummer is passed, it uses the one in the object.

TODO

Date validation

Check to make sure days and months actually are valid.

Organisationsnummer

Detect corporate and government identities. These numbers have the same format as personnummer.

Sex

Decide if the person is male or female.

Sammordningsnummer

A personnummer registered for a different purpose.

AUTHOR

Erik Bosrup, erik@bosrup.com

Copyright (c) 2001 Erik Bosrup. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1).