วิธีการสร้างเลขหลักที่ 13
Proc CheckPID
para _pid
priv _ret,_seek,_var,sumx
_ret=.F.
_seek=iif(type('_pid')#'C','',_pid)
_pid=''
for i=1 to len(_seek)
_var=subs(_seek,i,1)
if _var$'0123456789'
_pid=_pid+_var
endif
next
if len(_pid)=13
_ret=.T.
sumx = val(left(_pid,1)) * 13
for i = 2 to 12
sumx = sumx + val(subs(_pid,i,1)) * (14 - i)
next
if right(_pid,1) # right(str(11-mod(sumx,11)),1)
_ret=.F.
endif
endif
retu _ret
DelPhi
function TForm1.IDCheck(ID : String) :Boolean;
var i ,sumx ,modx : Integer;
str : String;
begin
for i := 1 to length(ID) do
begin
if ID in ['0'..'9'] then
begin
str := str + ID;
end;
end;
if Length(Str) = 13 then
begin
result := true;
sumx := strtoint(copy(str,1,1)) * 13 ;
for i := 2 to 12 do
begin
sumx := sumx + strtoint(copy(str,i,1)) * (14 - i);
end;
modx := sumx mod 11;
modx := 11 - modx;
if copy(str,length(str),1) <> copy(inttostr(modx),length(inttostr(modx)),1) then
result := false;
end
else result := false;
end;