public class PackIden
{
/// <summary>
/// 根据身份证获取生日
/// </summary>
/// <param name="cardid">身份证</param>
/// <param name="res">是否有格式(true1990-01-01,false19900101)</param>
/// <returns></returns>
public static string GetBirthdayByIdentityCardId(string cardid, bool res)
{
string birthday = string.Empty;
System.Text.RegularExpressions.Regex regex = null; if (cardid.Length == )
{
regex = new Regex(@"^\d{17}(\d|x)$");
if (regex.IsMatch(cardid))
{
if (res)
birthday = cardid.Substring(, ).Insert(, "-").Insert(, "-");
else
birthday = cardid.Substring(, );
}
else
{
birthday = "invalid cardid";
}
}
else if (cardid.Length == )
{
regex = new Regex(@"^\d{15}");
if (regex.IsMatch(cardid))
{
if (res)
birthday = cardid.Substring(, ).Insert(, "-").Insert(, "-");
else
birthday = cardid.Substring(, );
}
else
{
birthday = "invalid cardid";
}
}
else
{
birthday = "invalid cardid";
} return birthday;
} /// <summary>
/// 根据身份证获取身份证信息
/// 18位身份证
/// 0地区代码(1~6位,其中1、2位数为各省级*的代码,3、4位数为地、市级*的代码,5、6位数为县、区级*代码)
/// 1出生年月日(7~14位)
/// 2顺序号(15~17位单数为男性分配码,双数为女性分配码)
/// 3性别
///
/// 15位身份证
/// 0地区代码
/// 1出生年份(7~8位年,9~10位为出生月份,11~12位为出生日期
/// 2顺序号(13~15位),并能够判断性别,奇数为男,偶数为女
/// 3性别
/// </summary>
/// <param name="cardId"></param>
/// <returns></returns>
public static string[] GetCardIdInfo(string cardId)
{
string[] info = new string[];
System.Text.RegularExpressions.Regex regex = null;
if (cardId.Length == )
{
regex = new Regex(@"^\d{17}(\d|x)$");
if (regex.IsMatch(cardId))
{
info.SetValue(cardId.Substring(, ), );
info.SetValue(cardId.Substring(, ), );
info.SetValue(cardId.Substring(, ), );
info.SetValue(Convert.ToInt32(info[]) % != ? "男" : "女", );
}
}
else if (cardId.Length == )
{
regex = new Regex(@"^\d{15}");
if (regex.IsMatch(cardId))
{
info.SetValue(cardId.Substring(, ), );
info.SetValue(cardId.Substring(, ), );
info.SetValue(cardId.Substring(, ), );
info.SetValue(Convert.ToInt32(info[]) % != ? "男" : "女", );
}
} return info; } }