function checkidcard(sstr, byval ddate, byval nsex)
?checkidcard = "false"
?if isnull(sstr) or sstr = "" then exit function
?if not isdate(ddate) or ddate = "" then exit function
?if not isnumeric(nsex) or nsex = "" then exit function
?
?dim ore, sdate
?
?set ore??= new regexp
?ore.ignorecase?= true
?ore.global?= true
?
?nsex?= cint(nsex mod 2)
?sdate?= year(ddate) & dblnum(month(ddate)) & dblnum(day(ddate))
?
?select case len(sstr)
??case 8
???if datediff("yyyy", ddate, date()) < 19 then exit function
???ore.pattern?= "^[\d]{8}$"
???if not ore.test(sstr) then exit function
???if sstr <> sdate then exit function
??case 15
???ore.pattern?= "^[\d]{15}$"
???if not ore.test(sstr) then exit function
???if mid(sstr, 7, 6) <> right(sdate, 6) then exit function
???if cint(mid(sstr, 14, 1)) mod 2 <> nsex then exit function
??case 18
???ore.pattern?= "^(?:[\d]{18}|[\d]{17}x)$"
???if not ore.test(sstr) then exit function
???if mid(sstr, 7, 8) <> sdate then exit function
???if cint(mid(sstr, 17, 1)) mod 2 <> nsex then exit function
???
???dim nn, aw, ac, nl
???
???nn = 0
???aw = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
???ac = array("1", "0", "x", "9", "8", "7", "6", "5", "4", "3", "2")
???
???for nl = 1 to 17
????nn = nn + cint(mid(sstr, nl, 1)) * aw(nl - 1)
???next
???
???if ucase(right(sstr, 1)) <> ac(nn mod 11) then exit function
??case else
???exit function
?end select
?
?set ore??= nothing
?
?checkidcard = "true"
end function
function dblnum(nnum)
?dblnum = nnum
?if dblnum <10 then dblnum = "0" & dblnum
end function