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

  • Home
  • SEARCH
  • 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 8900961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:13:52+00:00 2026-06-15T01:13:52+00:00

I have a number that is generated in an X,XXX format (so it has

  • 0

I have a number that is generated in an X,XXX format (so it has commas). The numbers need to be styled (with a black background & white text) whereas the commas need to be as they are.

Anyway, I’m trying to add a span around each number in the string, but it doesn’t appear to be working.

function numberWithCommas(x) {
    var parts = x.toString().split(".");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    var stylednumbers = parts.join(".");
    var stylednumbers = stylednumbers.replace(/([0-9]+\.)/, '<span class="counternumber">$1</span>');
    return stylednumbers;
}

I am a bit of a javascript novice (and avoiding jQuery as well, as it’s WordPress), but keen to get it working. Any ideas on where I am going wrong?

Any further information that you need I’ll be happy to provide.

  • 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-06-15T01:13:54+00:00Added an answer on June 15, 2026 at 1:13 am

    I think you want your regexp to be /([0-9]+)/g, otherwise only the last three digits of your number will get spanned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets assume i have a bill number that has 12 numbers: 823 45678912 My
I have a number of applications that need a header file to be generated
Like my question, i need to generate random numbers that have identical pairs between
I have a number of files that are generated in a function defined as:
I have a selection list that is generated dynamically, it lists a number of
I have a number (e.g. 6) that is dynamically generated and I would like
I have a number that is generated dynamically, and I would like to add
I have an input string that's generated as in following example: string.Format(Document {0}, was
I have a TableLayout and some unknown number of TableRows that are generated based
I have a function that generates normal random number matrix having normal distribution using

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.