Norwegian personal number verification in C#

By | 2016-12-07

Code to verify Norwegian personal number (personnummer / fødselsnummer) written in C#.

Obeys 2013 standards as described in this Wikipedia article. Please let me know how if you find bugs / improvements. :)

(PS: This code is easy to test in LINQPad. Select C# Program, paste it in and hit run.)

2 thoughts on “Norwegian personal number verification in C#

  1. Jonny Strickley

    Hi Tedd,

    I am trying to apply similar logic to a Teradata SQL query. What I am trying to find out is how the 2nd checksum is calculated if the 1st produces an “X” i.e. the first checksum was 10 which is replaced with an “X” (according to several sources in Wiki, Google etc).

    e.g.

    181251490 becomes 122 when multiplying each digit by the weight and adding the result.

    122/11 = 11 remainder 1

    11-1 = 10

    Check digit is therefore X

    181251490 becomes 181251490X

    So I need to understand how to use mod11 on 181251490X

    (one source: http://www.pgrocer.net/Cis51/mod11.html)

    Thanks,
    Jonny

    Reply
    1. tedd Post author

      Hi

      For Norwegian birth numbers there is no X, only digits. If the mod11 result is 11 its changed to 0, if result is 10 then number is invalid. Second control digit follows the same rule with multipliers vs indexes changed.

      Br,
      Tedd

      Reply

Leave a Reply