C#台湾身份证合法性验证

國民身分證統一編號檢查方法

字母
數值
10
11
12
13
14
15
16
17
34
18
19
20
21
22
35
23
24
25
26
27
28
29
32
30
31
33

 
以國民身分證統一編號B120667503為例:
          區性       檢
          域別       查
          碼碼       碼
 
一、找出第一位英文字母的對應數值。
二、對應數值之個位數值乘以9,再加上十位數之值,其總和再除以10,所得之餘數為個位對應值:
  例:B之對應數值為11,則其個位對應值=0
  因為:【1+(1×9)】÷10,其餘數為0
三、經前述步驟將第一位英文字母轉換後,產生一個十位數字的數列:
  如:B1206675030120667503
四、再將這一數列依序乘以1、8、7、6、5、4、3、2、1
  0×1=00
  1×8=08
  2×7=14
  0×6=00
  6×5=30
  6×4=24
  7×3=21
  5×2=10
  0×1=00
     ―――
     107
五、再將此總和值除以10,再取其餘數
  107÷10 餘數7
六、再取這一餘數之補數
  7之補數為3

七、3與檢查碼相符,此國民身分證統一編號符合邏輯檢查。

#region 臺灣身份證號碼驗證
private bool CheckIDCard_CHT(string IDCard)
{
        string strFirstCode="";
        if(IDCard.Length!=10)
        {
                return false;//长度必需为10
        }
        if(IDCard.Substring(1,1)!="1"&&IDCard.Substring(1,1)!="2")
        {
                return false;//第二位必需是1=男或者2=女
        }
        switch(IDCard.Substring(0,1))
        {
                case "A":
                        strFirstCode="10";
                        break;
                case "B":
                        strFirstCode="11";
                        break;
                case "C":
                        strFirstCode="12";
                        break;
                case "D":
                        strFirstCode="13";
                        break;
                case "E":
                        strFirstCode="14";
                        break;
                case "F":
                        strFirstCode="15";
                        break;
                case "G":
                        strFirstCode="16";
                        break;
                case "H":
                        strFirstCode="17";
                        break;
                case "I":
                        strFirstCode="34";
                        break;
                case "J":
                        strFirstCode="18";
                        break;
                case "K":
                        strFirstCode="19";
                        break;
                case "L":
                        strFirstCode="20";
                        break;
                case "M":
                        strFirstCode="21";
                        break;
                case "N":
                        strFirstCode="22";
                        break;
                case "O":
                        strFirstCode="35";
                        break;
                case "P":
                        strFirstCode="23";
                        break;
                case "Q":
                        strFirstCode="24";
                        break;
                case "R":
                        strFirstCode="25";
                        break;
                case "S":
                        strFirstCode="26";
                        break;
                case "T":
                        strFirstCode="27";
                        break;
                case "U":
                        strFirstCode="28";
                        break;
                case "V":
                        strFirstCode="29";
                        break;
                case "W":
                        strFirstCode="32";
                        break;
                case "X":
                        strFirstCode="30";
                        break;
                case "Y":
                        strFirstCode="31";
                        break;
                case "Z":
                        strFirstCode="33";
                        break;
                default:
                        return false;
        }
        int iAllNum=Convert.ToInt32(strFirstCode.Substring(0,1))+
                Convert.ToInt32(strFirstCode.Substring(1,1))*9+
                Convert.ToInt32(IDCard.Substring(1,1))*8+
                Convert.ToInt32(IDCard.Substring(2,1))*7+
                Convert.ToInt32(IDCard.Substring(3,1))*6+
                Convert.ToInt32(IDCard.Substring(4,1))*5+
                Convert.ToInt32(IDCard.Substring(5,1))*4+
                Convert.ToInt32(IDCard.Substring(6,1))*3+
                Convert.ToInt32(IDCard.Substring(7,1))*2+
                Convert.ToInt32(IDCard.Substring(8,1))*1+
                Convert.ToInt32(IDCard.Substring(9,1))*1;
        if(iAllNum%10!=0)
        {
                return false;
        }
        return true;
}
#endregion
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值