欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#根據(jù)身份證號(hào)碼判斷出生日期和性別

 更新時(shí)間:2016年08月24日 10:45:02   作者:※WYF※  
這篇文章主要為大家詳細(xì)介紹了C#根據(jù)身份證號(hào)碼判斷出生日期和性別的方法,感興趣的小伙伴們可以參考一下

18位的身份證,前面六位代表了你戶籍所在地,第七位到第十四位代表了你的出生年月,第十五位到第十七為代表了你的性別(偶數(shù)為女,奇數(shù)為男),根據(jù)這一信息,我在系統(tǒng)開發(fā)的錄入員工的身份證后控件焦點(diǎn)轉(zhuǎn)移時(shí)根據(jù)身份證號(hào)碼獲得生日和性別。 

用C#寫的代碼如下:

/// <summary>
/// 在控件驗(yàn)證 textBox_IdentityCard 的 Validated事件中定義身份證號(hào)碼的合法性并根據(jù)身份證號(hào)碼得到生日和性別 
/// </summary>
private void textBox_IdentityCard_Validated(object sender, EventArgs e)
{
  try
  {
    //獲取得到輸入的身份證號(hào)碼
    string identityCard = textBox_IdentityCard.Text.Trim();
    if (string.IsNullOrEmpty(identityCard))

    {

      //身份證號(hào)碼不能為空,如果為空返回

      MessageBox.Show("身份證號(hào)碼不能為空!");

      if (textBox_IdentityCard.CanFocus)

      {

        textBox_IdentityCard.Focus();//設(shè)置當(dāng)前輸入焦點(diǎn)為textBox_IdentityCard

      }

      return;

    }

    else

    {

      //身份證號(hào)碼只能為15位或18位其它不合法

      if (identityCard.Length != 15 && identityCard.Length != 18)

      {

        MessageBox.Show("身份證號(hào)碼為15位或18位,請(qǐng)檢查!");

        if (textBox_IdentityCard.CanFocus)

        {

          textBox_IdentityCard.Focus();

        }

        return;

      }

    }
    string birthday = "";
    string sex = "";
    //處理18位的身份證號(hào)碼從號(hào)碼中得到生日和性別代碼
    if (identityCard.Length == 18)
    {
      birthday = identityCard.Substring(6, 4) + "-" + identityCard.Substring(10, 2) + "-" + identityCard.Substring(12, 2);
      sex = identityCard.Substring(14, 3);

    }<br>

    //處理15位的身份證號(hào)碼從號(hào)碼中得到生日和性別代碼
    if (identityCard.Length == 15)
    {
      birthday = "19" + identityCard.Substring(6, 2) + "-" + identityCard.Substring(8, 2) + "-" + identityCard.Substring(10, 2);
      sex = identityCard.Substring(12, 3);
    }<br>
    textBox_Birthday.Text = birthday;
    //性別代碼為偶數(shù)是女性奇數(shù)為男性
    if (int.Parse(sex) % 2 == 0)
    {
      this.comboBox_Sex.Text = "女";
    }

    else
    {
      this.comboBox_Sex.Text = "男";
    }
  }
  catch (Exception ex)

  {

    MessageBox.Show("身份證號(hào)碼輸入有誤");
    if (textBox_IdentityCard.CanFocus)
    {
      textBox_IdentityCard.Focus();
    }
    return;
  }
}

 以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • c#生成站點(diǎn)地圖(SiteMapPath)文件示例程序

    c#生成站點(diǎn)地圖(SiteMapPath)文件示例程序

    這篇文章主要介紹了c#生成站點(diǎn)地圖(SiteMapPath)文件的示例,大家參考使用
    2013-11-11
  • 深入C#任務(wù)管理器中應(yīng)用程序選項(xiàng)隱藏程序本身的方法詳解

    深入C#任務(wù)管理器中應(yīng)用程序選項(xiàng)隱藏程序本身的方法詳解

    本篇文章是對(duì)在C#任務(wù)管理器中應(yīng)用程序選項(xiàng)隱藏程序本身的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • Unity Shader實(shí)現(xiàn)素描效果

    Unity Shader實(shí)現(xiàn)素描效果

    這篇文章主要為大家詳細(xì)介紹了Unity Shader實(shí)現(xiàn)素描效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • C#實(shí)現(xiàn)日期格式轉(zhuǎn)換的公共方法類實(shí)例

    C#實(shí)現(xiàn)日期格式轉(zhuǎn)換的公共方法類實(shí)例

    這篇文章主要介紹了C#實(shí)現(xiàn)日期格式轉(zhuǎn)換的公共方法類,結(jié)合完整實(shí)例形式分析了C#針對(duì)各種常見日期格式的轉(zhuǎn)換方法,涉及C#字符串、日期、時(shí)間相關(guān)操作技巧,需要的朋友可以參考下
    2017-01-01
  • 最新評(píng)論