日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Lua身份证号校验

發(fā)布時(shí)間:2024/8/1 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Lua身份证号校验 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
--返回狀態(tài)標(biāo)識(shí) local status = {success = 0,error_length = 1,error_format = 2,error_address = 3,error_birthday = 4,error_code = 5, }--身份證長(zhǎng)度 local idLength = 18--有效省級(jí)地址碼 local provinceCode = {11, 12, 13, 14, 15,21, 22, 23,31, 32, 33, 34, 35, 36, 37, 71,41, 42, 43,44, 45, 46, 81, 82,51, 52, 53, 54, 50,61, 62, 63, 64, 65 }--校驗(yàn)碼(身份證最后一位)根據(jù)前面十七位數(shù)字碼,按照ISO7064:1983.MOD11-2校驗(yàn)碼計(jì)算出來(lái)的校驗(yàn)碼。 local checkCode = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2} local mappedCode = {"1", "0", "x", "9", "8", "7", "6", "5", "4", "3", "2"}--長(zhǎng)度檢測(cè) function isLengthOk(id)if #id ~= idLength thenreturn falseelsereturn trueend end--格式檢測(cè) function isFormatOk(id)if string.match(id, "%d+") == id or string.match(id, "%d+x") == id thenreturn trueelsereturn falseend end--地址檢測(cè) function isAddressOk(id)--省local province = tonumber(id:sub(1,2))local isProvinceOk = falsefor _,v in ipairs(provinceCode) doif province == v thenisProvinceOk = truebreakendend--市l(wèi)ocal city = tonumber(id:sub(3,4))local isCityOk = falseif city >= 1 and city <= 70 thenisCityOk = trueend--縣local county = tonumber(id:sub(5,6))local isCountyOk = falseif (county >= 1 and county <= 18) or (county >= 21 and county <= 99) thenisCountyOk = trueendif isProvinceOk and isCityOk and isCountyOk thenreturn trueelsereturn falseend end--出生日期檢測(cè) function isBirthdayOk(id)local y = tonumber(id:sub(7,10))local m = tonumber(id:sub(11,12))local d = tonumber(id:sub(13,14))local date = {year = y, month = m, day = d}local t = os.time(date)local revertDate = os.date("*t",t)if revertDate.year == date.year and revertDate.month == date.month and revertDate.day == date.day thenreturn trueelsereturn falseend end--校驗(yàn)碼檢測(cè) function isCheckCodeOk(id)local preId = id:sub(1,17)local nums = {}for c in preId:gmatch(".") dotable.insert(nums,tonumber(c))endlocal sum = 0for i,v in ipairs(nums) dosum = sum + v * checkCode[i]endif mappedCode[(sum%11+1)] == id:sub(18, 18) thenreturn trueelsereturn falseend end--身份證校驗(yàn) function verifyID(id)if not isLengthOk(id) thenreturn status.error_lengthendif not isFormatOk(id) thenreturn status.error_formatendif not isAddressOk(id) thenreturn status.error_addressendif not isBirthdayOk(id) thenreturn status.error_birthdayendif not isCheckCodeOk(id) thenreturn status.error_codeendreturn status.success end

總結(jié)

以上是生活随笔為你收集整理的Lua身份证号校验的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。