标签:style blog color ar sp div on log 代码
/// <summary> /// 通过身份证号码判断男女 /// </summary> /// <param name="strIDCard">空:不能为空。位数:位数不对。NULL:程序异常</param> public static string GetSexByIDCard(string strIDCard) { try { string strSex = ""; //获取得到输入的身份证号码 if (string.IsNullOrEmpty(strIDCard)) { //身份证号码不能为空,如果为空返回 strSex = "空"; return strSex; } else { //身份证号码只能为15位或18位其它不合法 if (strIDCard.Length != 15 && strIDCard.Length != 18) { strSex = "位数"; return strSex; } } //string birthday = ""; string sex = ""; //处理18位的身份证号码从号码中得到生日和性别代码 if (strIDCard.Length == 18) { //birthday = strIDCard.Substring(6, 4) + "-" + strIDCard.Substring(10, 2) + "-" + strIDCard.Substring(12, 2); sex = strIDCard.Substring(14, 3); } //处理15位的身份证号码从号码中得到生日和性别代码 if (strIDCard.Length == 15) { //birthday = "19" + strIDCard.Substring(6, 2) + "-" + strIDCard.Substring(8, 2) + "-" + strIDCard.Substring(10, 2); sex = strIDCard.Substring(12, 3); } //textBox_Birthday.Text = birthday; //性别代码为偶数是女性奇数为男性 if (int.Parse(sex)%2 == 0) { strSex = "女"; } else { strSex = "男"; } return strSex; } catch { return null; } }
支持15位和18位身份证。
标签:style blog color ar sp div on log 代码
原文地址:http://www.cnblogs.com/joysky/p/4059034.html