This does it incorrectly:
Can jQuery add commas while user typing numbers?
$('input.number').keypress(function(event){
if(event.which >= 37 && event.which <= 40){
event.preventDefault();
}
var $this = $(this);
var num = $this.val().replace(/,/g, '');
$this.val(num.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));
});
I need “1000000” to be “1,000,000” or better with spaces “1 000 000”.
Please help. Thanks.
if you wanted to have something like “1 000 000”, you can change the code to something like this.
Hope this helps