Validating credit cards

Tuesday 3 December 2002

I was doing some online shopping, and had to enter a credit card number. I entered my credit card number (using virtual card numbers, of course). I hit submit, and was prompted to enter a valid credit card number. Of course, what had happened was that I had entered my number with spaces between every four digits, as any normal person would do, and the stupid site would only accept the number with no spaces in it.

Why is this so hard? How many people a day get that idiotic message box? Looking at the source for the page, I found these snippets of JavaScript:

var cardPattern = /\d{16}/;

if (!(cardPattern.test(document.userInfo.cardNumber.value))) {
  errorMsg += 'Please enter a valid Card Number.\n';
  errorFlg = 1;
}

Why not do this:

var cardPattern = /\d{16}|\d{4} \d{4} \d{4} \d{4}/

and let me be? Why after all these years are average users still expected to pick up the slack for lazy programmers?

And don't tell me, "the back end wouldn't accept the string with spaces, so the front end is right to reject it"! Why can't the back end deal with the spaces?

Comments

Add a comment:

name
email
Ignore this:
not displayed and no spam.
Leave this empty:
www
not searched.
 
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.