PB身份证号码正确性校验

身份证号码校验(gf_check_identity)

可以同时对15位和18位的身份证进行校验,并自动根据平年和润年进行判断。可以在数据窗口ItemChanged事件中调用该函数进行校验。
/*-------------------------------------------------------------------------------
* 函数名称:Boolean gf_check_identity(string as_identity)
* 函数功能: 验证身份证号输入的正确性
* 参数说明: string      as_identity    身份证号
* 返 回 值: True  成功
*            False 失败
* 调用举例: gf_check_identity('410101650101101')  
* 尚未完善:没有对身份证号码的第18位校验位进行判断。因为我暂时没有找到第18位
* 的校验算法,等找到了我再加上。应该比较简单。
*--------------------------------------------------------------------------------*/
string ls_identity_no
string ls_year,ls_month,ls_day,ls_date
string ls_today
long ll_year
long ll_identity_no_len  

ls_identity_no = as_identity
ls_today = string(today(),'yyyy/mm/dd')

ll_identity_no_len=LEN(ls_identity_no)

if ls_identity_no = ''  then
MessageBox("系统提示","身份证号码不能为空!!",StopSign!,ok!)
return False
elseif ll_identity_no_len <> 15 AND ll_identity_no_len <> 18 then
MessageBox("系统提示","身份证号码位数不足,请检查输入情况!!",StopSign!,ok!)
return False
end if

if ll_identity_no_len = 15 then //身份证为 15 处理,  认为15位的年 = 19**
ls_year = mid(ls_identity_no, 7, 2)
ls_month = mid(ls_identity_no, 9, 2)
ls_day = mid(ls_identity_no, 11, 2)
ls_year = '19' + ls_year//year is only 20 century
ls_date = ls_year +'/' + ls_month +'/' + ls_day
else
ls_year = mid(ls_identity_no, 7, 4)
if Left(ls_year,2) <> '19' and left(ls_year,2) <> '20' then
MessageBox("系统提示","身份证号码中的出生年份不正确, 请您重新输入! ",StopSign!,ok!)
return False
end if
ls_month = mid(ls_identity_no, 11, 2)
ls_day = mid(ls_identity_no, 13, 2)
ls_date = ls_year +'/' + ls_month +'/' + ls_day
end if

if ls_month > '12' then
MessageBox("系统提示","身份证号码中的出生月份大于12, 请您重新输入 ",StopSign!,ok!)
return False
elseif ls_month < '1' then
MessageBox("系统提示","身份证号码中的出生月份小于01, 请您重新输入 ",StopSign!,ok!)
return False
end if

if ls_day < '01' then
MessageBox("系统提示","身份证号码的出生日小于01, 请您重新输入 !",StopSign!,ok!)
return False
end if

CHOOSE CASE ls_month
CASE '01','03','05','07','08','10','12'//大月的处理
if ls_day > '31' then
MessageBox("系统提示","身份证号码的出生日大于31, 请您重新输入 !",StopSign!,ok!)
return False
end if

CASE '04','06','05','09','11' //小月的处理
if ls_day > '30' then
MessageBox("系统提示","身份证号码的出生日大于30, 请您重新输入 !",StopSign!,ok!)
return False
end if
CASE '02'  //平年和闰年的处理
ll_year = long(ls_year)
if (mod(ll_year,4) = 0 and Mod(ll_year,100)<>0) or (Mod(ll_year,400) = 0) then   //闰年,二月份不能多于29天
if ls_day > '29' then
MessageBox("系统提示","闰年的二月份没有" + ls_day + "日,请重新输入出生日期!",StopSign!,ok!)
return False
end if
else//平年二月份不能大于28天
if ls_day > '28' then
MessageBox("系统提示","平年的二月份没有" + ls_day + "日,请重新输入出生日期!",StopSign!,ok!)
return False
end if
end if
END CHOOSE

if ls_date > ls_today then
MessageBox("系统提示","身份证号码的出生日期小于登记日期,不合理请您重新输入 !",StopSign!,ok!)
return False
end if

return True
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值