I have this code:
<input class="form-control only_number" id="milesamount_1" name="AboutYouDetail[miles_amount][1]" type="text">
$('.only_number').on('keypress keyup select change', function (evt) {
var nmbr = $(this).attr('id').split('_')
var milesamount = $('#milesamount_' + nmbr[1]).val()
var new_milesamount = String(milesamount).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
$('#milesamount_' + nmbr[1]).val(new_milesamount)
console.log(new_milesamount);
})
In the console the number is showing correctly say, if I input 123454342 it shows as 123,454,342 but in the input field it shows as 1,2,3,4,5,4,342
How do I fix this to show the , only after every 3 digits?