`
webcode
  • 浏览: 5952734 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics