初学VFP,请大家多多指教!!!!!
不足之处请指点。
因很多程序的人员记录会用到身份证号,为了减少录入错误而制定代码
代码如下:
*-----------------------------------------------------
* 从18位身份证号中提取生日
* 提取年 SUBSTR(ALLTRIM(Id_card),7,4)
* 提取月 SUBSTR(ALLTRIM(Id_card),11,2)
* 提取日 SUBSTR(ALLTRIM(Id_card),13,2)
* 从15位身份证号中提取生日
* 提取年 SUBSTR(ALLTRIM(Id_card),7,2)
* 提取年 SUBSTR(ALLTRIM(Id_card),9,2)
* 提取年 SUBSTR(ALLTRIM(Id_card),11,2)
* id_card是表单中的身份证号变量。以下同
*-----------------------------------------------------
local d_ok,
IF len(ALLTRIM(Id_card))=18
d_ok=SUBSTR(ALLTRIM(Id_card),7,4);
+"-"+SUBSTR(ALLTRIM(Id_card),11,2);
+"-"+SUBSTR(ALLTRIM(Id_card),13,2)
ELSE
d_ok="19"+SUBSTR(ALLTRIM(Id_card),7,2);
+"-"+SUBSTR(ALLTRIM(Id_card),9,2);
+"-"+SUBSTR(ALLTRIM(Id_card),11,2)
ENDIF
CTOD(d_ok)
*-----------------------------------------------------
* 接上:判断月份和日
* 返回真值身份证号正确,返回假值身份证号的出生月份或日期有误
* 不足之处:未能提示出一些小月的错误(如某月只有29日),可加入日期进行判断(请教)
*-----------------------------------------------------
BETWEEN(VAL(SUBSTR(ALLTRIM(dyok),5,2)),1,12) .or. BETWEEN(VAL(SUBSTR(ALLTRIM(dyok),7,2)),1,31)
*-----------------------------------------------------
* 18位的身份证号校验程序
* 假定身份证号的变量为Id_card
* 此代码未运行过,刚写完,请指教有没有更方便的方法?
*----------------------------------------------------
local cardsum,okc,yy
dimension Ai(17),Wi(17)
if len(ALLTRIM(Id_card))=18
store VAL(SUBSTR(ALLTRIM(Id_card),1,1)) to Ai(1)
store VAL(SUBSTR(ALLTRIM(Id_card),2,1)) to Ai(2)
store VAL(SUBSTR(ALLTRIM(Id_card),3,1)) to Ai(3)
store VAL(SUBSTR(ALLTRIM(Id_card),4,1)) to Ai(4)
store VAL(SUBSTR(ALLTRIM(Id_card),5,1)) to Ai(5)
store VAL(SUBSTR(ALLTRIM(Id_card),6,1)) to Ai(6)
store VAL(SUBSTR(ALLTRIM(Id_card),7,1)) to Ai(7)
store VAL(SUBSTR(ALLTRIM(Id_card),8,1)) to Ai(8)
store VAL(SUBSTR(ALLTRIM(Id_card),9,1)) to Ai(9)
store VAL(SUBSTR(ALLTRIM(Id_card),10,1)) to Ai(10)
store VAL(SUBSTR(ALLTRIM(Id_card),11,1)) to Ai(11)
store VAL(SUBSTR(ALLTRIM(Id_card),12,1)) to Ai(12)
store VAL(SUBSTR(ALLTRIM(Id_card),13,1)) to Ai(13)
store VAL(SUBSTR(ALLTRIM(Id_card),14,1)) to Ai(14)
store VAL(SUBSTR(ALLTRIM(Id_card),15,1)) to Ai(15)
store VAL(SUBSTR(ALLTRIM(Id_card),16,1)) to Ai(16)
store VAL(SUBSTR(ALLTRIM(Id_card),17,1)) to Ai(17)
store 7 to Wi(1)
store 9 to Wi(2)
store 10 to Wi(3)
store 5 to Wi(4)
store 8 to Wi(5)
store 4 to Wi(6)
store 2 to Wi(7)
store 1 to Wi(8)
store 6 to Wi(9)
store 3 to Wi(10)
store 7 to Wi(11)
store 9 to Wi(12)
store 10 to Wi(13)
store 5 to Wi(14)
store 8 to Wi(15)
store 4 to Wi(16)
store 2 to Wi(17)
cardsum=(Ai(1)*Wi(1)+Ai(2)*Wi(2)+Ai(3)*Wi(3)+Ai(4)*Wi(4)+Ai(5)*Wi(5)+Ai(6)*Wi(6)+Ai(7)*Wi(7);
+Ai(8)*Wi(8)+Ai(9)*Wi(9)+Ai(10)*Wi(10)+Ai(11)*Wi(11)+Ai(12)*Wi(12)+Ai(13)*Wi(13);
+Ai(14)*Wi(14)+Ai(15)*Wi(15)+Ai(16)*Wi(16)+Ai(17)*Wi(17))
yy=MOD(cardsum,11)
DO case
CASE yy=0
okc='1'
CASE yy=1
okc='0'
CASE yy=2
okc='X'
CASE yy=3
okc='9'
CASE yy=4
okc='8'
CASE yy=5
okc='7'
CASE yy=6
okc='6'
CASE yy=7
okc='5'
CASE yy=8
okc='4'
CASE yy=9
okc='3'
CASE yy=9
okc='2'
endcase
if okc=SUBSTR(ALLTRIM(Id_card),18,1)
MESSAGEBOX("校验通过",48,"提示窗口标题")
else
MESSAGEBOX("校验不通过",48,"提示窗口标题")
else
MESSAGEBOX("只能校验18位的身份证号",48,"提示窗口标题")
endif
*-----------------------------------------------------
* 从18位身份证号中提取判断性别数字
* VAL(SUBSTR(ALLTRIM(Id_card),17,1)
* 从15位身份证号中提取判断性别数字
* VAL(SUBSTR(ALLTRIM(Id_card),15,1)
*-----------------------------------------------------
IF len(ALLTRIM(Id_card))=18
cardsex=VAL(SUBSTR(ALLTRIM(Id_card),17,1))
ELSE
cardsex=VAL(SUBSTR(ALLTRIM(Id_card),15,1))
ENDIF
IIF(MOD(cardsex,2)=1,'男','女')
[此贴子已经被作者于2006-9-1 10:16:57编辑过]