0

I am wanting to know if its possible to take off commas from an input box when clicking a submit button using jQuery.

I am trying to take in a number value from users that automatically adds in commas for easier readability, ex: $1,000,000. I have gotten this running however when the user submits the data, our backend cannot read values anything else other than numbers so I am wanting to know if I can change the values with commas to just numbers when the user clicks the submit button?

Alex111
  • 167
  • 1
  • 4
  • 14

2 Answers2

4
$('#your-form').on('submit', function() {
    var input = $('#your-input');
    input.val(input.val().replace(/,/g, ''));
});
Deep
  • 2,472
  • 2
  • 15
  • 25
2

The better way do not store any chars exept numbers in such fileds. I usually use regex in such cases.

console.log($('#input').val().replace(/[^0-9]/g, "")); // result 1000000 

Then you can format value on show page as you wish. Later.


Best regards

Egor

Egor Malkevich
  • 1,516
  • 1
  • 11
  • 24