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 7405527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:25:01+00:00 2026-05-29T05:25:01+00:00

I format numbers using jqnumformatter plugin. Everything is fine with that but I’m having

  • 0

I format numbers using jqnumformatter plugin. Everything is fine with that but I’m having problems on removing the commas. I used .each() to loop through all the inputs which has commas on it. But in this case I need to click on the next button twice so that all the commas on the numbers will be removed.

<script>
$(function(){

    $("#next").click(function(){//unformats the numbers

        $("input[data-toformat=format]").each(function(){
            var formatted = $(this).val();
            var unformatted = formatted.replace(",", "");
            $(this).val(unformatted);
        });

    });


});
</script>

<input type="text" id="num" data-toformat="format"  autofocus/>
<input type="text" id="num2" data-toformat="format" />
<input type="button" id="next" value="next">
<input type="button" id="back" value="back">

Do you have a better way on doing this?It really fails to unformat the numbers all at once if I have 2 or more commas on each of the numbers.

  • 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-29T05:25:02+00:00Added an answer on May 29, 2026 at 5:25 am

    The problem is in the way you are calling the .replace() method:

    var unformatted = formatted.replace(",", ""); 
    

    If you pass a string as the first parameter it only replaces the first occurrence. If you pass a regular expression you can set the regex “global” flag to replace all occurrences:

    var unformatted = formatted.replace(/,/g, "");
    

    Note that your code can be simplified quite a bit because you don’t really need the local variables:

    $(this).val( $(this).val().replace(/,/g, "") );
    

    But it can be simplified even further because if you pass a function to the .val() method you don’t even need the .each() loop:

    $(function(){
       $("#next").click(function(){
           //unformats the numbers
           $("input[data-toformat=format]").val(function(i, oldVal){
               return oldVal.replace(/,/g, "");
           });
       });
    });
    

    This syntax for .val() will pass the old (current) value of each element to the function you supply, setting the new value to the return from that function.

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

Sidebar

Related Questions

Using String.Format how can i ensure all numbers have commas after every 3 digits
I'm trying to write something that format Brazilian phone numbers, but I want it
I'm looking for a way to format numbers using tokens. This needs to be
I want to call a number in below format using platformRequest: platformRequest(tel:*123*33584744#); But it
Hi I want to format float numbers such that it will be displayed as
I want to print a list of numbers, but I want to format each
Using .net To add a $ symbol for numbers I did Texbox1.Text.Format = C
I am using String.Format({0:C2}, -1234) to format numbers. It always formats the amount to
I am trying to conditionally format the numbers that appear in a NumericAxis axis
I am using C# to try and format a range in Excel as numbers.

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.