身份证号的较验
18位身份证号码由17位数字本
s--省、直辖市、自治区
q--市、地区(北京市除密云和
x--县(如北京市为:东城区0
y--出生年
m--出生月
d--出生日
n--顺号(顺序码,表示在同一
j--较验码(随机在11个数字
声明:以下代码从csdn的网友
<%@ WebService Language="c#" Class="WeatherW
using System;
using System.Collecti
using System.Componen
using System.Data;
using System.Diagnost
using System.Web;
using System.Web.Serv
namespace WeatherWS
{
/// <summary>
/// checkID 的摘要说明。
/// </summary>
[WebService(Nam
public class checkCID : System.Web.Serv
{
public checkCID()
{
InitializeCompo
}
#region 组件设计器生成的代码
//Web 服务设计器所必需的
private IContainer components = null;
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeCompo
{
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Disp
}
base.Dispose(di
}
#endregion
[WebMethod(Desc
public idDataClass CheckCidInfo(st
{
string[] aCity = new string[]{null,n
double iSum=0;
idDataClass _cidData = new idDataClass();
System.Text.Reg
System.Text.Reg
if(!mc.Success)
{
_cidData.isVali
_cidData.chkInf
return _cidData;
}
if(cid.Length==
cid = cid.ToLower();
cid = cid.Replace("x"
if(aCity[int.Pa
{
_cidData.isVali
_cidData.chkInf
return _cidData;
}
try
{
DateTime.Parse(
}
catch
{
_cidData.isVali
_cidData.chkInf
return _cidData;
}
for(int i=17;i>=0;i--)
{
iSum +=(System.Math.
}
if(iSum%11!=1)
{
_cidData.isVali
_cidData.chkInf
return _cidData;
}
_cidData.isVali
_cidData.chkInf
return _cidData;
}
//将15位身份证号码转换为18位
private string convert15to18(s
{
char[] strJiaoYan = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
int[] intQuan = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1};
string strTemp;
int intTemp = 0;
strTemp = cid.Substring(0
for (int i=0;i<=strTemp.
{
intTemp += int.Parse(strTe
}
intTemp = intTemp % 11;
return strTemp + strJiaoYan[intT
}
}
//用于保存身份证验证结果的类
public class idDataClass
{
public idDataClass()
{
}
public bool isValid;
public string chkInfo;
}
}