中國(guó)身份證號(hào)碼驗(yàn)證
來(lái)源:易賢網(wǎng) 閱讀:814 次 日期:2015-02-12 10:00:28
溫馨提示:易賢網(wǎng)小編為您整理了“中國(guó)身份證號(hào)碼驗(yàn)證”,方便廣大網(wǎng)友查閱!

using System;

/// <summary>

/// Summary description for IDCardValid

/// </summary>

public class IDCardValid

{

public IDCardValid()

{

//

// TODO: Add constructor logic here

//

}

/// <summary>

/// 驗(yàn)證身份證號(hào)碼

/// </summary>

/// <param name="Id">身份證號(hào)碼</param>

/// <returns>驗(yàn)證成功為T(mén)rue,否則為False</returns>

public static bool CheckIDCard(string Id)

{

if (Id.Length == 18)

{

bool check = CheckIDCard18(Id);

return check;

}

else if (Id.Length == 15)

{

bool check = CheckIDCard15(Id);

return check;

}

else

{

return false;

}

}

#region 身份證號(hào)碼驗(yàn)證

/// <summary>

/// 驗(yàn)證15位身份證號(hào)

/// </summary>

/// <param name="Id">身份證號(hào)</param>

/// <returns>驗(yàn)證成功為T(mén)rue,否則為False</returns>

private static bool CheckIDCard18(string Id)

{

long n = 0;

if (long.TryParse(Id.Remove(17), out n) == false || n < Math.Pow(10, 16) || long.TryParse(Id.Replace('x', '0').Replace('X', '0'), out n) == false)

{

return false;//數(shù)字驗(yàn)證

}

string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";

if (address.IndexOf(Id.Remove(2)) == -1)

{

return false;//省份驗(yàn)證

}

string birth = Id.Substring(6, 8).Insert(6, "-").Insert(4, "-");

DateTime time = new DateTime();

if (DateTime.TryParse(birth, out time) == false)

{

return false;//生日驗(yàn)證

}

string[] arrVarifyCode = ("1,0,x,9,8,7,6,5,4,3,2").Split(',');

string[] Wi = ("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2").Split(',');

char[] Ai = Id.Remove(17).ToCharArray();

int sum = 0;

for (int i = 0; i < 17; i++)

{

sum += int.Parse(Wi[i]) * int.Parse(Ai[i].ToString());

}

int y = -1;

Math.DivRem(sum, 11, out y);

if (arrVarifyCode[y] != Id.Substring(17, 1).ToLower())

{

return false;//校驗(yàn)碼驗(yàn)證

}

return true;//符合GB11643-1999標(biāo)準(zhǔn)

}

/// <summary>

/// 驗(yàn)證18位身份證號(hào)

/// </summary>

/// <param name="Id">身份證號(hào)</param>

/// <returns>驗(yàn)證成功為T(mén)rue,否則為False</returns>

private static bool CheckIDCard15(string Id)

{

long n = 0;

if (long.TryParse(Id, out n) == false || n < Math.Pow(10, 14))

{

return false;//數(shù)字驗(yàn)證

}

string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";

if (address.IndexOf(Id.Remove(2)) == -1)

{

return false;//省份驗(yàn)證

}

string birth = Id.Substring(6, 6).Insert(4, "-").Insert(2, "-");

DateTime time = new DateTime();

if (DateTime.TryParse(birth, out time) == false)

{

return false;//生日驗(yàn)證

}

return true;//符合15位身份證標(biāo)準(zhǔn)

}

#endregion

}

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
上一篇:Fastcgi是什么
易賢網(wǎng)手機(jī)網(wǎng)站地址:中國(guó)身份證號(hào)碼驗(yàn)證
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)