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 updat
replace
var noCommas = $('.money').text().replace(/,/g, ''),
asANumber = +noCommas;
Less is more! (sometimes!)
$(document).ready(function(){
var **stripString** = $('.money').text().replace(/,/g, '');
$('.*money*').text(**stripString**);
});
Could you please try with this , will remove comma on click on textbox , after focusout thousand seperated will be added...
$( "#salary" ).click(function() {
$( "#salary" ).val( $("#salary").val().replace(/,/g, ''));
});
$( "#salary" ).blur(function() {
$( "#salary" ).val( addCommas($( "#salary" ).val());
});
function addCommas(nStr) {
nStr += '';
var x = nStr.split('.');
var x1 = x[0];
var x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
you can do like this
var str=$(".money").text();
var str2= str.replace(",", "")
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!
use replace function of javascript for removing , in a string
var result = jQuery('.money').html().replace(',', '');
alert(result);