Tuesday, July 22, 2014

C'mon, can't I leave spaces in my credit card number? It's 2014!

Probably you've had this experience ... filling out a purchase form to buy something online and entering the credit card number exactly as it appears on the card, say:

4444 5555 6666 7777

You click Submit and you get back (quickly via Javascript or less quickly with a page refresh) something like:


Why the hell should I have to remove the spaces in the form in this day and age?

To be fair, a few companies get this right, Amazon among them. Others refuse to let you put in a space some Javascript trick as you're typing. This is better than an error message, but not much. Finally, some remove spaces after you hit submit but before you finalize your purchase on another page. This is silly but tolerable.

Let me say this clearly: the display of the credit card number does not need to look exactly like the credit card number that's transmitted to the back end system.

Humans aren't good at parsing a 16-digit number; we need spaces or dashes to break up the pieces of the number.

Web geeks must just be missing the code to do this, so I will provide some examples here in hope of putting this issue to rest for all of us for the future.

Javascript:

var card = '4444 5555 6666 7777';
var cnostr = card.replace(/\s+/g, '');
alert('card b4:' + card);
alert('card after:' + cnostr);

Python:

import re
card = '4444 5555 6666 7777'
(cnostr,ign) = re.subn('[\s+]','',card)
print 'card = %s' % card
print 'cnostr = %s' % cnostr

Other languages are left as an exercise for the reader.

How about this, folks? Please send a link to this page to the purveyor of any web form that doesn't allow you to put spaces in a credit card number. We can start to get this fixed!








1 comment:

Mark McWiggins said...

Just wanted to give credit where credit is due: I made a reservation via La Quinta's website lq.com, and wonder of wonders they allowed me to put spaces in the credit card I used in the reservation and handled it correctly.

Hooray!