下面是我从网上查到(具体什么网忘了)身份证校验码产生方法:(我已编程试过十几个身份证号)
∑(ai×Wi)(mod 11)……………………………………(1)公式(1)中:
i----表示号码字符从由至左包括校验码在内的位置序号;
ai----表示第i位置上的号码字符值;
Wi----示第i位置上的加权因子,其数值依据公司Wi=2(n-1)(mod 11)计算得出。i  18 17 16 15 14 13 12 11 10  9 8 7  6 5 4 3 2 1Wi 7  9  10  5  8  4  2  1  6  3 7 9 10 5 8 4 2 1
根据公式(1)进行计算,然后根据计算的结果,从下面的表中查出相应的校验码,其中X表示计算结果为10:∑(ai×WI)(mod 11)   0 1 2 3 4 5 6 7 8 9 10
校验码字符值ai       1 0 X 9 8 7 6 5 4 3 2

解决方案 »

  1.   

    '//所有的函数用VB语言声明,用PbScript书写'////////////////////////////由身份证号获取生日
    public function card_id_birth (byval string p_card_id) as date
    date birth
    If len(trim(p_card_id)) = 15 Then
    birth = date("19"+Mid(p_card_id,7,2)+"-"+&
    Mid(p_card_id,9,2)+"-"+Mid(p_card_id,11,2))
    ElseIf len(trim(p_card_id)) = 18 Then
    birth = date(Mid(p_card_id,7,4)+"-"+&
    Mid(p_card_id,11,2)+"-"+Mid(p_card_id,13,2))
    End IfIf birth = date("1900-01-01") then 
       messagebox("输入错误","身份证号码中关于出生年月的信息不对!",Exclamation!,ok!)
    // sle_card_id.setfocus()
    Return 1900-01-01
    End Ifreturn birth
    end function'///////////////////////////////////////////////////////////
    '由身份证号获取性别
    public function card_id_sex(byval p_card_id as string)
    integer I_card_numIf len(p_card_id) = 15 Then 
    I_card_num = Integer(Right(p_card_id,1))
    ElseIf len(p_card_id) = 18 Then 
    I_card_num = Integer(Mid(p_card_id,17,1))
    Else
    messagebox("注意","身份证号码输入有误,请重试!",Exclamation!,ok!)
    Return string(3)
    End IfIf Mod(I_card_num,2) = 0 Then
    Return string(2) //女
    Else
    Return string(1)
    End If 
    end function'/////////////////////////////////////////////////////////
    '获取当前年龄
    public function card_id_to_bith(byval card_id)as integer
    date birth
    Integer i_age
    If len(trim(card_id)) = 15 Then
    birth = date("19"+Mid(card_id,7,2)+"-"+&
    Mid(card_id,9,2)+"-"+Mid(card_id,11,2))
    ElseIf len(trim(card_id)) = 18 Then
    birth = date(Mid(card_id,7,4)+"-"+&
    Mid(card_id,11,2)+"-"+Mid(card_id,13,2))
    End IfIf birth = date("1900-01-01") then 
       messagebox("输入错误","身份证号码中关于出生年月的信息不对!",Exclamation!,ok!)
    // sle_card_id.setfocus()
    Return 0
    End Ifi_age = Year(today()) - Year(birth)
    return i_age
    end function
    '////////////////////////////////////////////////////////////////
    '将15位转为18位
    public function card_id15to18(byval card_id15 as string ) as string
    integer i,num=0
    string card_id18,code
    card_id18=left(card_id15,6)+'19'+right(card_id15,9)
    for i=18 to 2 step -1
    num=num+mod(2^(i - 1),11)*integer(mid(card_id18,19 - i,1))
    next
    num=mod(num,11)
    CHOOSE CASE num
    CASE 0
    code='1'
    CASE 1
    code='0'
    CASE 2
    code='X'
    CASE 3
    code='9'
    CASE 4
    code='8'
    CASE 5
    code='7'
    CASE 6
    code='6'
    CASE 7
    code='5'
    CASE 8
    code='4'
    CASE 9
    code='3'
    CASE 10
    code='2'
    END CHOOSE
    card_id18=card_id18+code
    return card_id18
    end function
    '////////////////////////////////////////////////////////////////////////
    '18位身份证根据校验位验证是否合法
    public function card18_valid(byval card_id18 as  string ) as boolean
    integer i,num=0
    string code
    for i=18 to 2 step -1
    num=num+mod(2^(i - 1),11)*integer(mid(card_id18,19 - i,1))
    next
    num=mod(num,11)
    CHOOSE CASE num
    CASE 0
    code='1'
    CASE 1
    code='0'
    CASE 2
    code='X'
    CASE 3
    code='9'
    CASE 4
    code='8'
    CASE 5
    code='7'
    CASE 6
    code='6'
    CASE 7
    code='5'
    CASE 8
    code='4'
    CASE 9
    code='3'
    CASE 10
    code='2'
    END CHOOSEif right(card_id18,1)<>code then
    return false
    else
    return true
    end if
    end function