sfzhm=ALLTRIM(thisform.text3.Value )
IF !empty(sfzhm)
DIMENSION a(18),w(18)
*W(i)----表示第i位置上的加权因子
w(18)=7
w(17)=9
w(16)=10
w(15)=5
w(14)=8
w(13)=4
w(12)=2
w(11)=1
w(10)=6
w(9)=3
w(8)=7
w(7)=9
w(6)=10
w(5)=5
w(4)=8
w(3)=4
w(2)=2
w(1)=1
*!*
zs=.f.
DO
case
CASE
len(allt(sfzhm))=18
*a(18)表示号码字符从右至左包括校验码字符在内每个位置上的字符
j=18
FOR
i=1 to 18
a(j)=subs(sfzhm,i,1)
j=j-1
ENDFOR
*求号码的每个对应的字符与其对应的加权因子乘积之和并求其与11的余数
s=0
FOR
i=2 to 18
s=s+VAL(ALLTRIM(a(i)))*W(i)
ENDFOR
y=mod(s,11)
**校验其校验位是否正确
DO
case
CASE
y=0
IF
val(allt(a(1)))<>1
=messagebox("身份证号码有误!",0x10,"提示信息")
thisform.text2.Value=0
=''
thisform.text3.Value =''
ELSE
csnyr=date(val(subs(allt(sfzhm),7,4)),val(subs(allt(sfzhm),11,2)),val(subs(allt(sfzhm),13,2)))
IF
mod(val(subs(allt(sfzhm),15,3)),2)<>0
xb="男"
else
xb="女"
ENDIF
=xb
Thisform.text2.Value =Year(tmpaddresses.serverdate)-Year(csnyr)
*!*
zs=.t.
ENDIF
CASE
y=1
IF
val(allt(a(1)))<>0
=messagebox("身份证号码有误!",0x10,"提示信息")
thisform.text2.Value=0
=''
thisform.text3.Value =''
ELSE
csnyr=date(val(subs(allt(sfzhm),7,4)),val(subs(allt(sfzhm),11,2)),val(subs(allt(sfzhm),13,2)))
IF
mod(val(subs(allt(sfzhm),15,3)),2)<>0
xb="男"
ELSE
xb="女"
ENDIF
=xb
Thisform.text2.Value =Year(tmpaddresses.serverdate)-Year(csnyr)
*!*
zs=.t.
ENDIF
CASE
y=2
IF
allt(a(1))<>"X"
=messagebox("身份证号码有误!",0x10,"提示信息")
thisform.text2.Value=0
=''
thisform.text3.Value =''
ELSE
csnyr=date(val(subs(allt(sfzhm),7,4)),val(subs(allt(sfzhm),11,2)),val(subs(allt(sfzhm),13,2)))
IF mod(val(subs(allt(sfzhm),15,3)),2)<>0
xb="男"
ELSE
xb="女"
ENDIF
=xb
Thisform.text2.Value =Year(tmpaddresses.serverdate)-Year(csnyr)
*!*
zs=.t.
ENDIF
CASE
y>=3
IF
val(allt(a(1)))+y<>12
=messagebox("身份证号码有误!",0x10,"提示信息")
thisform.text2.Value=0
=''
thisform.text3.Value =''
ELSE
csnyr=date(val(subs(allt(sfzhm),7,4)),val(subs(allt(sfzhm),11,2)),val(subs(allt(sfzhm),13,2)))
IF
mod(val(subs(allt(sfzhm),15,3)),2)<>0
xb="男"
ELSE
xb="女"
ENDIF
=xb
Thisform.text2.Value =Year(tmpaddresses.serverdate)-Year(csnyr)
*!*
zs=.t.
ENDIF
ENDCASE
**将15位身份证号码转换为18位
CASE
len(allt(sfzhm))=15
**将15位身份证号出生年前加上"19"
sfzhm=subs(allt(sfzhm),1,6)+"19"+subs(allt(sfzhm),7,9)
**将带有19的17位号码赋值给数组
j=18
FOR
i=1 to 17
a(j)=subs(sfzhm,i,1)
j=j-1
ENDFOR
*号码的每个对应的字符与其对应的加权因子乘积之和并求其与11的余数
s=0
FOR
i=2 to 18
s=s+val(allt(a(i)))*W(I)
ENDFOR
y=mod(s,11)
**求校验号
DO
case
CASE
y=0
a(1)="1"
CASE
y=1
a(1)="0"
CASE
y=2
a(1)="X"
CASE
y>=3
a(1)=allt(str(12-y))
ENDCASE
**将15位转换为18位的号码
sfzhm=sfzhm+a(1)
csnyr=date(val(subs(allt(sfzhm),7,4)),val(subs(allt(sfzhm),11,2)),val(subs(allt(sfzhm),13,2)))
IF
mod(val(subs(allt(sfzhm),15,3)),2)<>0
xb="男"
ELSE
xb="女"
ENDIF
=xb
Thisform.text2.Value =Year(tmpaddresses.serverdate)-Year(csnyr)
*!*
zs=.t.
**如果输入的位数少于15位
CASE
len(allt(sfzhm))<15
=messagebox("您输入的身份证号码位数不正确!",0x10,"提示信息")
thisform.text3.Value =''
thisform.text2.Value=0
=''
ENDCASE
thisform.refresh
ENDIF