Skip to content

Validate Swedish identity numbers (personal number and co-ordination number)

License

Notifications You must be signed in to change notification settings

ullenius/personnummer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Personnummer

GitHub Workflow Status

Validate Swedish personal identity numbers.

Installation

Add the package to your maven or gradle configuration.
If you prefer to use the package from github rather than maven-central, add the repository as well.

<dependency>
  <groupId>dev.personnummer</groupId>
  <artifactId>personnummer</artifactId>
  <version>3.*.*</version>
</dependency> 
plugins {
    id 'maven'
}

repositories {
    // If using maven central
    mavenCentral()
    // If you wish to use github
    maven {
      url "https://github.com/personnummer/java:personnummer"
    }
}

dependencies {
    configuration("dev.personnummer:personnummer")
}

For more information on how to install and authenticate with github packages, check this link.

Examples

Validation

import dev.personnummer.*;

class Test 
{
  public void TestValidation() 
  {
    Personnummer.valid("191212121212");    // => True
    Personnummer.valid("121212+1212");     // => True
    Personnummer.valid("20121212-1212");   // => True
  }
}

Format

// Short format (YYMMDD-XXXX)
(new Personnummer("1212121212")).format();
// => 121212-1212

// Short format for 100+ years old
(new Personnummer("191212121212")).format();
//=> 121212+1212

// Long format (YYYYMMDDXXXX)
Personnummer.parse("1212121212").format(true);
//=> 201212121212

Age

(new Personnummer("1212121212")).getAge();
//=> 7

Get sex

(new Personnummer("1212121212")).isMale();
//=> true
Personnummer.parse("1212121212").isFemale();
//=> false

See src/test//PersonnummerTest.java for more examples.

License

MIT

About

Validate Swedish identity numbers (personal number and co-ordination number)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%