in reply to Simple formatting question for credit card number

Not to be a stick in the mud, but please remember that not all credit cards are 16 digits long. For instance, AMEX is 15 digits (4-6-5 or s/(.{4})(.{6})(.{5})/$1 $2 $3/) and some VISA cards are 13 digits (4-3-3-3 or s/(.{4})(.{3})(.{3})(.{3})/$1 $2 $3 $4/).

On a side note, you can use Business::CreditCard to tell what type of credit card you are dealing with as well as whether or not the credit card's checksum is valid.

Hope this helps.

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1

  • Comment on Re: Simple formatting question for credit card number

Replies are listed 'Best First'.
Re: Re: Simple formatting question for credit card number
by simonm (Vicar) on Aug 12, 2003 at 23:22 UTC
    If you end up with a simple function that normalizes the punctuation of various credit cards based on type, I'd suggest submitting it as a contribution to Business::CreditCard. It'd be a nice contribution and an obvious place for people to look for it in the future.