• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

http://4kcan.com/s/MTAzMQ==

Related Code
Check if the Civic Registration number for Finland is valid

Check if the Civic Registration number for Norway is valid


0
81 0 0 0 0 0

 private static readonly int[] WeightsNoK1 = new[] { 3, 7, 6, 1, 8, 9, 4, 5, 2 };
    private static readonly int[] WeightsNoK2 = new[] { 5, 4, 3, 2, 7, 6, 5, 4, 3, 2 };

    public bool IsCivicRegistrationNumberValid(string civicNumber)
    {
        if (civicNumber == null)
            return false;

        var cleanedCivicNumber = civicNumber.Replace("-", "");

        if (!IsNumeric(cleanedCivicNumber))
            return false;

        if (cleanedCivicNumber.Length != 11)
            return false;

        if (!IsDateValid(cleanedCivicNumber.Substring(0, 6), "ddMMyy", "nb-NO"))
            return false;

        int sum = 0;
        for (int i = 0; i < 9; i++)
        {
            sum += WeightsNoK1[i] * int.Parse(cleanedCivicNumber.Substring(i, 1));
        }
        int k1 = 11 - sum % 11;
        if (k1 == 11)
        {
            k1 = 0;
        }

        if (k1.ToString() != cleanedCivicNumber.Substring(9, 1))
        {
            return false;
        }

        sum = 0;
        for (int i = 0; i < 10; i++)
        {
            sum += WeightsNoK2[i] * int.Parse(cleanedCivicNumber.Substring(i, 1));
        }

        int k2 = 11 - sum % 11;
        if (k2 == 11)
        {
            k2 = 0;
        }

        if (k2.ToString() != cleanedCivicNumber.Substring(10, 1))
        {
            return false;
        }

        return true;
    }
}

Share: twitter | facebook   Action: used | fork | flag

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

civicregnumber

Mark 'civicregnumber' tag as 'like'

Mark 'civicregnumber' tag as 'ignore'


 Tommy
200
December 09, 2011 8:22 AM

Fork

 Check if the Civic Registration number for Norway is valid - Tommy Friday 09, 2011 8:22 AM


0 Feedback


You must log in before you can give any feedback


0 Discussion(s)

Newest Oldest

You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010