data eft_valid eft_invalid; input acct_nbr $ 1-30; length Add It ; /* check length for Visa/Discover/MC/Amex */ if length(acct_nbr) not in (15,16) then do; put 'WARNING: Not 15/16 digits: ' acct_nbr=; output eft_invalid; /* to stop processing, uncomment out the delete statement */ /* delete;*/ end; /* check for known test credit card number accounts */ /* reference: https:// if acct_nbr in ( '378282246310005' '371449635398431' '378734493671000' '6011111111111117' '6011000990139424' '5555555555554444' '5105105105105100' '4111111111111111' '4012888888881881' '4222222222222') then do; put 'WARNING: test credit card number: ' acct_nbr=; output eft_invalid; /* to stop processing, uncomment out the delete statement */ /* delete;*/ end; /* Luhn algorithm (also called modulus 10 or mod 10) */ /* mostly copied from Patrick

thread ID=4274 */ Chk Sum = 0; /* reset */ Chk Str=left(reverse(acct_nbr)); do pos=1 to length(Chk Str); if mod(pos,2) then /* odd positions */ do; Add It=substr(Chk Str,pos,1); end; else /* even positions: digit*2 */ do; Add It=put(2*input(substr(Chk Str,pos,1),2.),2.); end; /* add digits */ do i=1 to length(Add It); Chk Sum input(substr(Add It,i,1),2.); end; end; /* Check if ID is valid or not (if Chk Sum ends with Zero) */ if mod(Chk Sum,10)=0 then do; put 'NOTE: This is a valid ID: ' acct_nbr= Chk Sum=; output eft_valid; end; else if mod(Chk Sum,10) ne 0 then do; put 'WARNING: This is a invalid ID: ' acct_nbr= Chk Sum=; output eft_invalid; end; drop Chk Sum i pos Chk Str Add It; datalines; 378282246310005 371449635398431 378734493671000 6011111111111117 6011000990139424 5555555555554444 5105105105105100 4111111111111111 4012888888881881 4222222222222 123456789 3847592 48573726264859560 2843759 00028434305834 442308239586 ; run; Patrick’s SAS code was very helpful, but without resetting Chk Sum, SAS would fail all credit card numbers following an invalid card number. This code was tested with SAS 9.3 64-bit on Windows 7.

That way you will be able to check your code easier. If it's a single use script, you probably don't have a need for a function.

(s0,s1,s2,s3), (s1,s2,s3,s4), (s2,s3,s4,s5), ..." a, b, c, d = itertools.tee(iterable, 4) next(b, None) next(c, None) next(c, None) next(d, None) next(d, None) next(d, None) return zip(a, b, c, d) def val_rep(num): return not any( all(head == item for item in (a, b, c)) for head, a, b, c in quadwise(num) ) def valid_creditcard(card): groups = re.match(REGEX, card) if not groups: return False if card.count('-') not in (0, 3): return False return val_rep(''.join(groups.groups())) if __name__ == '__main__': total_count = int(raw_input()) cards = [ raw_input() for count in range(total_count) ] for card in cards: if valid_creditcard(card): print('Valid') else: print('Invalid') import re PATTERN = "([4-6])([0-9]-? )([0-9])" def is_valid_creditcard(sequence): """Check if a sequence is a valid credit card number.

Sequence must not: -Use any other separator; -Have 4 or more consecutive repeated digits.

NET to process online credit card orders, it is a good idea if you can perform some sort of validation on the credit card number before submitting it to your processor.

""" # do your stuff here We're missing the four consecutive digits.

This is now tricky, since it's not clear whether the hyphens are part of the run. ([0-9])$' def is_valid_card_number(sequence): """Returns `True' if the sequence is a valid credit card number.

Still, web-based merchants are not entirely helpless in their fraud prevention efforts and have at their disposal plenty of tools to assist them in the card validation process and should implement the following best practices: Using the Mod 10 algorithm for checking the validity of your customers’ card numbers will help protect your business against fraud or an error on the part of the cardholder and minimize related disputes and losses.

Major credit card issuing networks (including Visa, Master Card, Discover, and American Express) allow simple credit card number validation using the Luhn Algorithm (also called the “modulus 10” or “mod 10” algorithm).

To solve this issue on default payment methods: * make sure that you are indeed using multiple CC methods and have form elements with same names in your page source * make sure which method causes you the trouble cc or ccsave.phtml from this base theme folder and copy to your template folder payment/cc.phtml or payment/cc_save.phtml , clear cache .

Card-not-present transactions present merchants with fraud prevention challenges that are either non-existent or much easier to address in a card-present environment.

At the moment you would have to duplicate your code somewhat just to check a second credit card.