Coder Social home page Coder Social logo

swe-id-num's Introduction

SweIdNum Build status Build Status NuGet

Validate swedish identity numbers

Installation

Add the GlobalPhone nuget package to your app. For example, using Package Manager Console:

PM> Install-Package SweIdNum

Examples

c#

First make sure to import the relevant namespaces

using SweIdNum;
using SweIdNum.Core;

Then you can parse swedish personal identity numbers

try{
  var tolvansson = PersonalIdentityNumbers.Parse("121212-1212");
  var birthdate = tolvansson.GetDate();
} catch (DoesNotMatchFormatException){
  // ...
} catch (InvalidChecksumException){
  // ...
}

If you don't want to handle potential exceptions then you use the TryParse method

if (PersonalIdentityNumbers.TryParse("121212-1212", out tolvansson)) 
{
  // to stuff
}

f#

First make sure to import the relevant namespaces. In the code below we import the module PersonalIdentityNumbers for brevity.

open SweIdNum;
open SweIdNum.Core.PersonalIdentityNumbers

Note that the parse below will throw an exception if you feed it an invalid value

let tolvansson = parse "121212-1212"
let birthdate = getDate tolvansson 

If you are unsure if it's correct and want to handle it in a more f#y way, then use tryParse

let maybeTolvansson = tryParse "121212-1212"
match maybeTolvansson with
| Choice1Of2 tolvansson -> 
    //...
| Choice2Of2 err ->
    match err with
    | DoesNotMatchFormat -> //...
    | InvalidChecksum (expected,actual) -> //...

Influences

R package sweidnumbr

swe-id-num's People

Contributors

wallymathieu avatar

Stargazers

 avatar

Watchers

 avatar  avatar

swe-id-num's Issues

Samordningsnummer och testpersonnummer

Personnummer och samordningsnummer som går att testa med finns dokumenterade på skatteverkets hemsida.

Samordningsnummer används i många sammanhan varför det kan vara vettigt att implementera dessa:
https://www.skatteverket.se/privat/skatter/internationellt/bosattutomlands/samordningsnummer.4.53a97fe91163dfce2da80001279.html

Att testa med riktiga personnummer/samordningsnummer kan strida mot lag, varför det är bättre att använda skatteverkets testnummer

Dessa är i synnerhet vettiga att använda i t.ex. enhetstester och integrationstester.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.