/// <summary> /// 是否是有效的中国大陆身份证[严格校验] /// </summary> public static bool IsChinaPRIDCard(string idCardNo) { if (string.IsNullOrEmpty(idCardNo)) { return(false); } var tmpType = idCardNo.Length; var tmpIndex = idCardNo.Length - 1; var tmpValue = idCardNo.Remove(tmpIndex); if (!RegExpHelper.IsAllNumber(tmpValue, (uint)tmpIndex, (uint)tmpIndex) || ConvertHelper.GetLong(tmpValue, 0) < Math.Pow(10, tmpIndex - 1)) { return(false); } var provinceCodes = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91"; if (provinceCodes.IndexOf(idCardNo.Remove(2)) < 0) { return(false); } var interval = tmpType == 15 ? 2 : 0; var birthday = ConvertHelper.GetDateTime(idCardNo.Substring(6, 8 - interval).Insert(6 - interval, "-").Insert(4 - interval, "-")); if (birthday < InternalConstant.DefaultMSdbMinDate) { return(false); } if (tmpType == 15) { return(true); } // 继续18位校验 var allCsNumber = new string[] { "1", "0", "x", "9", "8", "7", "6", "5", "4", "3", "2" }; var allWiNumber = new int[] { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 }; var allAiNumber = ConvertHelper.Cast <int>(tmpValue.ToList().ConvertAll((item) => { return(item.ToString()); })).ToArray(); var sum = 0; for (int i = 0; i < tmpIndex; i++) { sum += allAiNumber[i] * allWiNumber[i]; } var mod = 0; Math.DivRem(sum, 11, out mod); if (allCsNumber[mod] != idCardNo.Substring(tmpIndex, 1).ToLower()) { return(false); } return(true); }
/// <summary> /// 获取中文星期[如"星期日"] /// </summary> /// <param name="dateString">符合日期格式的字符串</param> /// <returns></returns> public static string GetChineseWeekName(string dateString) { try { var dayOfWeek = (int)ConvertHelper.GetDateTime(dateString).DayOfWeek; var weekdays = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; return(weekdays[dayOfWeek]); } catch { } return(dateString); }