Validating credit cards

Tuesday 3 December 2002This is almost 22 years old. Be careful.

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:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.