C\#주민등록번호 검사

2001 단어 주민등록증
코드 발췌http://topic.csdn.net/u/20101231/09/039bdd22-3f0a-4bbb-908e-d887b4d7bbfe.html?19933
public static class Util

{

    // <summary>

    ///            

    /// 2010-10-13 jorln

    /// </summary>

    /// <param name="num">    </param>

    /// <param name="sex">  </param>

    /// <returns></returns>

    public static bool CheckIdentity(string num, string sex)

    {

        bool isIden = false;

        if (Convert.ToInt32(num.Substring(6, 4)) > 1850 && Convert.ToInt32(num.Substring(6, 4)) < 2010 && Convert.ToInt32(num.Substring(10, 2)) <= 12 && Convert.ToInt32(num.Substring(12, 2)) <= 31)

        {

            if (num.Substring(10, 2) == "02" && Convert.ToInt32(num.Substring(10, 2)) > 29)

                return isIden;

            if ((Convert.ToInt32(num.Substring(16, 1)) % 2 == 0 && sex == " ") || (Convert.ToInt32(num.Substring(16, 1)) % 2 != 0 && sex == " "))

            {

                int count = 0;

                int[] iden = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, };

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

                {

                    count += Convert.ToInt32(num.Substring(i, 1)) * iden[i];

                }

                int cc = count % 11;

                char num18 = cc == 0 ? '1' : (cc == 1 ? '2' : (cc == 2 ? 'X' : (cc == 3 ? '9' : (cc == 4 ? '8' : (cc == 5 ? '7' : (cc == 6 ? '6' : (cc == 7 ? '5' : (cc == 8 ? '4' : (cc == 9 ? '3' : '2')))))))));

                isIden = num.Substring(17, 1).ToUpper() == num18.ToString() ? true : false;



            }

        }

        return isIden;

    }

}

좋은 웹페이지 즐겨찾기