Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 206519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:39:12+00:00 2026-05-11T17:39:12+00:00

Some fancy websites show an error dialog when it is detected that an untrained

  • 0

Some fancy websites show an error dialog when it is detected that an untrained shopper has entered a credit/debit card number as it is printed on their card with spaces. Is it possible in some way to write a Java web app that handles these numbers with spaces as if they were correct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:39:12+00:00Added an answer on May 11, 2026 at 5:39 pm

    My view is that any Web app that rejects a credit card number with spaces isn’t doing its job. When you receive a credit card number, it’s easy enough to do:

    String ccNumber = ccNumber.replaceAll("[\\s-]+", "");
    

    to remove spaces and dashes (some use those too). Then validate the result. You’ll simply annoy your users if you force them to remove spaces you could just as easily do.

    As for how to validate, well that depends on a lot of things, such as which Web framework you’re using and what validation options you’ve chosen. Struts 1 for example might or might not use Apache Commons Validator whereas Spring MVC will (probably) use Spring validation and so on. So I can’t tell you exactly how to validate but I can tell you what to validate.

    The first thing is that a CC number with spaces should not be rejected. Most people will find:

    4123 0987 8876 2939
    

    much easier to read than:

    4123098788762939
    

    which is really important if the user misses or mistypes a digit and needs to find why his or her credit card number failed validation. The replaceAll() at the top of this post covers this situation.

    The second thing is that you display the credit card number (even when some of the digits are replaced with X for security reasons) in the correct way. I suggest you read through Anatomy of Credit Card Numbers.

    That page gives you the rules for the number of digits and the valid prefixes. A robust Web application will implement these so you can tell if a credit card number is invalid before you try and use it. It can take up to 30 seconds (or possibly more) to submit credit card details to a payment gateway so you shouldn’t do it until you are sure as you can be that the payment will be accepted. To do otherwise is to provide a really bad user experience. There is every chance the user will give up if it fails 1-2 times rather than wait.

    As for displaying them, that depends on the # of digits:

    • 16: 4 groups of 4 separated by a space;
    • 15: like an American Express card ie 4-6-5 with a space between each group;
    • 14: like a Diners Club card ie 4-6-4 with a space between each group;
    • 13: Never seen 13 but 4-5-4 or 4-4-5 or 5-4-4 (or possibly 3-3-3-4) springs to mind.

    The credit card number should be verified according to the checksum algorithm mentioned in the page before submitting for processing as part of a standard validation routine. That page has a Java implementation of that routine.

    Every website that accepts credit card payment should be doing all of the above as an absolute minimum or you’re simply throwing away business as a percentage of your users get frustrated.

    So the short version is two simple rules:

    1. Be as forgiving as possible with user input; and
    2. Do absolutely everything possible to validate credit card details prior to submission.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to save a email (from GMail), that has some fancy things, like
in some websites that i saw, urls are fancy and it contains text only.
I have a custom control that will do some fancy stuff, once it knows
I see some websites use fancy icons. An example is this curly leaf icon
Say that you want to do some fancy formatting of some tabular output from
I've got some lists inside lists to make some fancy drop-down menus. e.g <ul>
I'm fairly new to Ruby on Rails, and I'm attempting to create some fancy
In my form fancy select boxes are used. Which resulting in creating some spans
I've written some simple online games using purely HTML5 and JavaScript. Nothing fancy, no
Some time ago I've read an article on CLR, where author showed that if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.