Giter Club home page Giter Club logo

kennitalajs's Introduction

Kennitalajs

Validation for an Icelandic kennitala (social security number)

Getting started:

Install with npm (npm install kennitalajs) or:

<script type="text/javascript" src="https://npmcdn.com/kennitalajs@latest/kennitala.min.js"></script>

<script type="text/javascript">
    var test = new Kennitala(2202863399);

    console.log(test);
</script>

Accepted types:

//Kennitalajs accepts all types of possible kt formats
var type1 = 2202863399; //Integer
var type2 = '2202863399' //String
var type3 = '220286-3399' //String with the widely used hyphen

// I do however reccommend storing the kennitala in a string format since integers cant start with a zero

Validating a persons kennitala

var kennitala = new Kennitala(2202863399);
//kennitala returns:
{
    valid: true, //<----------- Tells us if the kennitala is valid
    type: 'person', //<-------- Tells us if kennitala belongs to a person or a company
    age: 22, //<--------------- The person/company age in years
    msAge: 694383374545, //<--- Time in milliseconds since birth/company was founded
    birthdayToday: true, //<--- Tells us if the person/company has a birthday today
    kt: 2202863399 //<--------- The kennitala as a integer
};

Validating a company kennitala

var kennitala = new Kennitala('521110-0660');
//kennitala returns:
{
    valid: true,
    type: 'company',
    age: 5,
    msAge: 174515150922,
    birthdayToday: true,
    kt: 5211100660
};

Invalid date examples

We can recieve 5 possible reasons for when the kennitala is not valid:

Kennitala can be too short

var kennitala = new Kennitala(22028633);

//kennitala returns:
{
    valid: false,
    reason: 'Kennitala is too short',
    errorCode: 1
};

Something is wrong with digits 1 and 2

XXxxxxxxxx:

var kennitala = new Kennitala(3202863399);

kennitala returns:
{
    valid: false,
    reason: 'Birthdate is out of range (digits 1 and 2)',
    errorCode: 2
};

Something is wrong with digits 3 and 4

xxXXxxxxxx

var kennitala = new Kennitala(2222863399);
//kennitala returns:
{
    valid: false,
    reason: 'Month digits are out of range (digits 3 and 4)',
    errorCode: 3
};

xxxxXXXxxx Digits 5,6,7 and 8 can be anything so we cant validate them


Something is wrong with digit number 9

xxxxxxxxXx

var kennitala = new Kennitala(2202863349);
//kennitala returns:
{
  valid: false,
    reason: 'Digit 9 is not valid. Read about "Níundi stafurinn" here: https://is.wikipedia.org/wiki/Kennitala',
    errorCode: 4
};

Something is wrong with digit number 10

xxxxxxxxxX

// 
var kennitala = new Kennitala(2202863393);

//kennitala returns:
{
    valid: false,
    reason: 'Century digit out of range (digit 10)',
    errorCode: 5
};

kennitalajs's People

Contributors

olitomas avatar

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.