>Alain has very nicely merged our two functions into one which uses >the Luhn algorithm to check the validity of account number and return >the card type from the account number. > Wow, there's some complex-looking stuff in there. Must have been translated from c++ or something. Would you believe that this... >FOR i = 0 TO L - 1 >cc( i) = val&( CHR$( ccNum[i + 1] ) ) >LONG IF( i MOD 2 != 0 AND L MOD 2 != 0) ¬ >OR( i MOD 2 = 0 AND L MOD 2 = 0 ) >cc( i ) = cc( i ) < < 1 >LONG IF cc( i ) > = 10 >temp = STR$( cc( i ) ) >cc( i ) = val&( CHR$( temp[2] ) ) ¬ > + val&( CHR$( temp[3] ) ) >END IF >END IF >NEXT i > >FOR i = 0 TO L - 1 >value + = cc( i ) >NEXT i ...all boils down to this?... >FOR i = 1 TO L >temp = ccNum[i] and 15 >LONG IF L - i and 1 >temp += temp >IF temp > 9 then temp -= 9 >END IF >value += temp >NEXT i Here's a purtified version of the whole thing. 0"0 =J= a y " '----------- BEGIN FB^3 CODE ------------ '~FN CCVERIFY$ (Credit card verifier) // Contributed 10-30-01 // Alain Pastor and Ken Shmidheiser LOCAL MODE LOCAL FN CCVerify$( ccNum AS STR63 ) DIM i, L, value, twoChars, fourChars, temp DIM ccType AS STR63 ccType = "Unknown Credit Card Type" value = 0 L = ccNum[0] temp = 0 FOR i = 1 TO L select ccNum[i] case _" " : temp ++ case < _"0", > _"9" : EXIT fn case else : ccNum[i-temp] = ccNum[i] end select NEXT i L -= temp ccNum[0] = L twoChars = {@ccNum[1]} fourchars = [@ccNum[1]] SELECT L CASE 16 SELECT ccNum[1] CASE _"5" IF ccNum[2] > = _"1" AND ccNum[2] < = _"5"¬ THEN ccType = "MasterCard" CASE _"4" : ccType = "VISA" CASE _"3" : ccType = "JCB" CASE _"6" if fourchars = _"6011" then ccType = "Discover" END SELECT CASE 15 SELECT CASE twoChars = _"34", twoChars = _"37" ccType = "AMEX" CASE fourchars = _"2014", fourchars = _"2149" ccType = "enRoute" CASE fourchars = _"2131", fourchars = _"1800" ccType = "JCB" END SELECT CASE 14 SELECT twoChars CASE _"30" LONG IF ccNum[3] > = _"1" AND ccNum[3] < = _"5" ccType = "Diners Club/Carte Blanche" END IF CASE _"36", _"38" ccType = "Diners Club/Carte Blanche" END SELECT CASE 13 IF ccNum[1] = _"4" THEN ccType = "VISA" END SELECT LONG IF ccType != "Unknown Credit Card Type" FOR i = 1 TO L temp = ccNum[i] and 15 LONG IF L - i and 1 temp += temp IF temp > 9 then temp -= 9 END IF value += temp NEXT i LONG IF value mod 10 = 0 ccType = "Valid " + ccType + " Credit Card Number" XELSE ccType = "Invalid Credit Card Number" END IF END IF END FN = ccType DIM cc AS STR255 cc = "4417 1258 2618 8868" PRINT FN CCVerify$( cc ) DO UNTIL FN BUTTON '-------------- END FB^3 CODE -------------