身份证号正则表达式-中文名-出生日期-电话号码-数字正则

发布于 2015-02-24 16:47 分类:编程开发来源:本站阅读(204) 评论(0) 身份证号码正则

private bool CheckIDCard(string Id)

{

if (Id.Length == 18)

{

bool check = CheckIDCard18(Id);

return check;

}

else if (Id.Length == 15)

{

bool check = CheckIDCard15(Id);

return check;

}

else

{

return false;

}

}

private bool CheckIDCard18(string Id)

{

long n = 0;

if (long.TryParse(Id.Remove(17), out n) == false || n < Math.Pow(10, 16) || long.TryParse(Id.Replace('x', '0' ).Replace('X', '0'), out n) == false)

{

return false;//数字验证

}

string address = "11x22x35x44x53x12x23x36x45x54x13 x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82 x91";

if (address.IndexOf(Id.Remove(2)) == -1)

{

return false;//省份验证

}

string birth = Id.Substring(6, 8).Insert(6, "-") .Insert(4, "-");