Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Commas with Jquery

Tags:

jquery

php

I am in need of some code that removes commas from a string. I currently have a variety of numbers in the number_format() for PHP. I use Jquery to post certain things to a update page and I need the commas removed from a class.

for instance here is some code.

<span class="money">1,234,567</span>

I want the value of the code I post to be 1234567 instead of 1,234,567. I would like to use Jquery if that's possible.

Thanks

like image 639
Devyn Avatar asked Oct 18 '11 03:10

Devyn


People also ask

How to remove commas in jquery?

Sometimes, we may need to remove the comma, semicolon, colon etc from the string in our jquery code. So at that time we can do this simply remove comma by using js replace(). Jquery replace() through we can easily replace the comma into empty string on that way comma will be remove from the jquery string.

How to remove comma from integer in jquery?

This is a clean way to get rid of the commas in one line, without loops. var cleanNumber = $("#selector"). val(). split(",").

How to remove comma from array in jquery?

What you can also do is just send the array as an array! var formUrl = 'explorer. php'; var $form = $("<form action='"+ formUrl +"' method='post'></form>") . append("<input type='hidden' name='form_submitted' value='true'>") .

How to replace comma in jquery?

Use a regex with the g flag instead of a string: . replace(/,/g, "") .


2 Answers

replace

var noCommas = $('.money').text().replace(/,/g, ''),
    asANumber = +noCommas;
like image 128
Joe Avatar answered Oct 02 '22 20:10

Joe


This is a clean way to get rid of the commas in one line, without loops.

    var cleanNumber = $("#selector").val().split(",").join("");

Hope can help u!

like image 23
Peyu_Atrellu Avatar answered Oct 02 '22 18:10

Peyu_Atrellu