Türkçe   |   English
Calendar
Categories
Archive
Links
Blogroll
Files

T.C. Identity Number correctness validation - 10.05.2008

There is a hash algorithm which makes us able to validate T.C. Identity Number that we take as an input in our projects. You can find the method that checks this hash below.

        private bool ValidateNumber(string parNumber)

        {

            for (int i = 0; i < parNumber.Length; i++)

            {

                if (!(char.IsNumber(parNumber[i]))) return false;

            }

 

            return true;

        }

        public void ValidateTCIdentityNumber(string TCIdentityNumber)

        {

            if (ValidateNumber(TCIdentityNumber.Trim()))

            {

                if (TCIdentityNumber.Trim().Length < 11)

                {

                    throw new Exception("T.C. Kimlik Numarası 11 karakterden az olamaz. Lütfen kontrol ediniz.");

                }

                else

                {

                    decimal identityNumberDecimal = Convert.ToDecimal(TCIdentityNumber.Trim());

                    decimal temp = Math.Floor(identityNumberDecimal / 100);

                    decimal temp1 = Math.Floor(identityNumberDecimal / 100);

                    int[] D = new int[10];

                    for (int n = 9; n >= 1; n--)

                    {

                        D[n] = (int)temp1 % 10;

                        temp1 = Math.Floor(temp1 / 10);

                    }

                    int oddSum = D[9] + D[7] + D[5] + D[3] + D[1];

                    int evenSum = D[8] + D[6] + D[4] + D[2];

                    int total = oddSum * 3 + evenSum;

                    int ChkDigit1 = (10 - (total % 10)) % 10;

                    oddSum = ChkDigit1 + D[8] + D[6] + D[4] + D[2];

                    evenSum = D[9] + D[7] + D[5] + D[3] + D[1];

 

                    total = oddSum * 3 + evenSum;

                    int ChkDigit2 = (10 - (total % 10)) % 10;

                    temp = (temp * 100) + (ChkDigit1 * 10) + ChkDigit2;

                    if (temp != identityNumberDecimal)

                    {

                        throw new Exception("T.C. Kimlik Numaranızı kontrol ediniz.");

                    }

                }

            }

            else

            {

                throw new Exception("T.C. Kimlik Numarası yalnızca rakamlardan oluşmalıdır. Lütfen kontrol ediniz.");

            }

        }

 

Clues,Codes

18.05.2008 - Oğuz Kurumlu
TC identity number's first 10 number's total's last number is equals TC identity number's 11. number

19.05.2008 - Bir Dost
Nedir sizdeki bu ingilizce hastalığı anlayamıyorum. İnanamıyorum gerçekten, yorumlarda ingilizce yapılmış. Well done m8.

19.05.2008 - Tamer Öz
İçeriği türkçe takip etmek isteyen kullanıcılar site üzerinde bulunan türkçe linkini kullanabilirler veya http://www.tameroz.com/tr/default.aspx adresine gidebilirler.
http://www.tameroz.com

21.05.2008 - Oğuz Kurumlu
Yazı ingilizce olup altına türkçe yorum yapılması pek bi manidar olurdu heralde :) (şekil 1.a) :)
Add Comment
First Name Last Name
Web Site
E-Mail
Comment
Security Picture

Photos

Dinner nearby Charles Bridge
Show All
Entries
News
Articles