Web Applications Stack Exchange is a question and answer site for power users of web applications. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this credit card number in a Google Docs spreadsheet of the following format:


How can I make it display like XXXX XXXX XXXX XXXX or XXXX-XXXX-XXXX-XXXX where they're in four digit blocks?

share|improve this question
Have you tried formatting the cell as Plain text and then editing the number to display in the credit card format? – Alex Feb 12 '12 at 23:06
up vote 5 down vote accepted

With dashes (-):


or with spaces ():

=CONCATENATE(LEFT(A1,4)&" "&MID(A1,5,4)&" "&MID(A1,9,4)&" "&RIGHT(A1,4))

share|improve this answer
I can't make a comment for some reason (I guess my rep is too low), but it's worth noting that @Raystafarian's answer (currently top rated) can cause serious harm if the spreadsheet is ever analyzed without the formatting (i.e. parsed by an application) as it will hide input mistakes. Example: Input: 1000100010001000 Output: 1000-1000-1000-1000 Input: 10001000100010001000 Output: 1000 1000 1000 1000 – Koviko Feb 16 '12 at 23:15
@Koviko I know I'm about 3 years late here, but in this case, the formula output is most likely in a different column than the raw data and any application (etc) would most likely use the raw data column, as it may (or may not) just print the formula if using the display column. Your disclaimer is valid if not using the raw data column, thanks! – Raystafarian Apr 15 '15 at 9:29

Try this:

=REGEXREPLACE(text("1234567890123456", "####,####"), ",", "-")

=REGEXREPLACE(text("1234567890123456", "####,####"), ",", " ")


1st: 1234-5678-9012-3456

2nd: 1234 5678 9012 3456

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.