歡迎跟我連絡

本頁最下方有Web MSN可以直接跟我交談喔!
免安裝程式...哈哈 歡迎聊天

2009年8月12日 星期三

中華民國身分證驗證程式碼

驗證規則,如下圖所示




C#程式碼:
public bool CheckIdentificationId(string Input_ID)
{
bool IsTrue = false;
if (Input_ID.Length == 10)
{
Input_ID = Input_ID.ToUpper();
if (Input_ID[0] >= 0x41 && Input_ID[0] <= 0x5A)
{
int[] Location_No = new int[] { 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 };
int[] Temp = new int[11];
Temp[1] = Location_No[(Input_ID[0]) - 65] % 10;
int Sum = Temp[0] = Location_No[(Input_ID[0]) - 65] / 10;
for (int i = 1; i <= 9; i++)
{
Temp[i + 1] = Input_ID[i] - 48;
Sum += Temp[i] * (10 - i);
}
if (((Sum % 10) + Temp[10]) % 10 == 0)
{
IsTrue = true;
}
}
}
return IsTrue;
}

應用範例:
bool Result = CheckIdentificationId(textBox_ID.Text);

0 個回應:

MSN狀態(我在線上時,可以跟我交談喔)