Created
August 19, 2014 03:59
-
-
Save reinaldorauch/011ac7f09de7df0c05c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function TFmPrinc.validaCartaoCredito(cn: String): ShortInt; | |
var | |
i, j, Sum : Integer; | |
begin | |
if (Length(cn) > 20) OR (Length(cn) < 15) then | |
Result := -1 | |
else | |
try | |
Sum := 0; | |
for i := Length(cn) - 1 downto 1 do | |
begin | |
j := Length(cn) - i; | |
if(j mod 2 = 1) then | |
inc(sum, StrToInt(cn[i])) | |
else | |
begin | |
J := StrToInt(cn[i]) * 2; | |
if(J > 9) then | |
inc(sum, (StrToInt(IntToStr(J)[1]) + StrToInt(IntToStr(J)[2])) * 2) | |
else | |
inc(sum, J); | |
end; | |
end; | |
if((10 - (Sum mod 10)) = StrToInt(cn[Length(cn)])) then | |
Result := 1 | |
else | |
Result := -1; | |
except | |
Result := -1; | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment