Delphi function for LUHN checking. Note that this is ok for credit cards
but some types of Debit (EFTPOS) cards dont seem to use this standard!

function CheckLuhn(const sEftCard: string): Boolean;
var
  sCard: string;
  i, iOddEven, iTot, iDigit: Integer;
begin
  Result := True;

  try
    if pos('=', sEftCard) = 0 then
      sCard := sEftCard else
      sCard := Copy(sEftCard, 1, pos('=', sEftCard) - 1);
    iOddEven := 0;
    iTot := 0;
    for i := length(sCard) downto 1 do begin
      iDigit := StrToInt(copy(sCard, i, 1));
      if iOddEven mod 2 <> 0 then begin
        case iDigit of
          0: iDigit := 0; // 2*0=0
          1: iDigit := 2; // 2*1=2
          2: iDigit := 4; // 2*2=4
          3: iDigit := 6; // 2*3=6
          4: iDigit := 8; // 2*4=8
          5: iDigit := 1; // 2*5=10 = 1+0 = 1
          6: iDigit := 3; // 2*6=12 = 1+3 = 3
          7: iDigit := 5; // 2*7=14 = 1+4 = 5
          8: iDigit := 7; // 2*8=16 = 1+6 = 7
          9: iDigit := 9; // 2*9=18 = 1+8 = 9
        end;
      end;
      Inc(iOddEven);
      iTot := iTot + iDigit;
    end;
    Result := ((iTot mod 10) = 0);
  except
    Result := False;
  end;


#####################################################################################
This e-mail message has been scanned for Viruses and Content by both MailMarshal and 
Norton's Antivirus.

Attention:
The information contained in this message and or attachments is intended only for the 
person or entity to which it is addressed and may contain confidential and/or 
privileged 
material.  Any review, retransmission, dissemination or other use of, or taking of any 

action in reliance upon, this information by persons or entities other than the 
intended
recipient is prohibited.  If you received this in error, please contact the sender and 

delete the material from any system and destroy any copies.

Please note that the views and opinions expressed in this message may be those 
of the individual and not necessarily those of Foodstuffs (South Island) Ltd
#####################################################################################
^Á—š•©Ý
éi†%,z» ®‹©
éi†"â²×^–˜buéi†*+‚|Öy»"µèm¶ŸÿÃ
zZaŠŠàŸ4èRt®nǧu隊[h–+-±êïuéi†*+‚|ðŠØ[¡Ü¨~éì¹»®&Þuéi†%žl
܆+ÞjØm¶ŸÿÃ&j)Z­Èb½ç(›÷^–˜bãG^–˜b¢¸'Ï


Reply via email to