Displaying Credit Card format

Cecil

19+ years progress programming and still learning.
Hi all.

I am trying to find an industry standard for displaying credit card numbers. Easy I here you cry. However credit card numbers range from 12 to 19 digits long.

Now I don't want to do credit card validation. I just want to write a function which displays these formats depending of there length. i.e. if I pass 1234444556778888 returns 1234 4445 5677 8888

I have created a table of what I think the display formats should be. If any one could correct or point me in the right direction. Thanks

xxxx xxxx xxxx 12 4 + 4 + 4
1111 2222 3333 12

xxxx xxx xxx xxx 13 4 + 3 + 3 + 3
1111 222 333 444 13

xxxx xxxxx xxxxx 14 4 + 5 + 5
1111 22223 33344 14

xxxxxx xxx xxx xxx 15 6 + 3 + 3 + 3
111111 222 333 444 15

xxxx xxxx xxxx xxxx 16 4 + 4 + 4 + 4
1111 2222 3333 4444 16

xxxx xxxx xxxx xxxx x 17 4 + 4 + 4 + 4 + 1
1111 2222 3333 4444 5 17

xxxx xxxx xxxx xxxx xx 18 4 + 4 + 4 + 4 + 2
1111 2222 3333 4444 55 18

xxxx xxxx xxxx xxxx xxx 19 4 + 4 + 4 + 4 + 3
1111 2222 2222 3333 444 19
 

Jupiter

Member
Still it seems easy. But in case of different formats there should be some signal to the function which format to choose. Let us suppose there are five different formats for five different credit card types then you can store the formatting info in the database based on the card type and run a single procedure to do the formatting on the supplied string.

Let us suppose that the maximum number of groups is 10 (e.g in 1524 1234 1223 53, the card number has four groups) this can be stored in database as 4442000000.

There may be other options too. You can write hardcoded logic for card types and store the procedure names in the database and run the procedure as
Code:
Run value (proc-name).

But the former logic seems better.
 
Top