根据身份证获取性别生日等信息

(1)根据身份证获取性别

方法1:

private string sex(string identityCard)

{

string sex = "";

//处理18位的身份证号码从号码中得到生日和性别代码

if (identityCard.Length == 18)

{

sex = identityCard.Substring(14, 3);

}

//处理15位的身份证号码从号码中得到生日和性别代码

if (identityCard.Length == 15)

{

sex = identityCard.Substring(12, 3);

}

//性别代码为偶数是女性奇数为男性

if (Int_32(sex) % 2 == 0)

{

sex = "女";

}

else

{

sex = "男";

}

return sex;

}

方法2:

public static bool reg_idcard(string _card)

{

Regex reg = new Regex(@"^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X|x)$");

if (reg.IsMatch(_card))

{

return true;

}

return false;

}

方法3:

public static string getSex(string _card)

{

int sex = int.Parse(_card.Substring(16, 1));

if (sex % 2 == 0)

{

return "女";

}

else

{

return "男";

}

}

(2) 根据身份证获取生日

private string birthday(string identityCard)

{

string birthday = "";

//处理18位的身份证号码从号码中得到生日和性别代码

if (identityCard.Length == 18)

{

birthday = identityCard.Substring(6, 4) + "-" + identityCard.Substring(10, 2) + "-"+ identityCard.Substring(12, 2);

}

//处理15位的身份证号码从号码中得到生日和性别代码

if (identityCard.Length == 15)

{

birthday = "19" + identityCard.Substring(6, 2) + "-" + identityCard.Substring(8, 2)+ "-" + identityCard.Substring(10, 2);

}

return birthday;

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值