Morgari Morgari - 1 month ago 12
HTML Question

Dividing thousands number for the field

When I'm texting the number in my text (or number) field I need the number to be divided by thousands with a comma.

Example

1. instead of it saying “1000” make it say “1,000”.
2. “1000000” make it say “1,000,000”.

Answer

Using Script

$(document).on('keyup', '.Amount', function() {
    var x = $(this).val();
    $(this).val(x.toString().replace(/,/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","));
});

Live Demo Here

Snippet Example Below

$(document).on('keyup', '.Amount', function() {
    var x = $(this).val();
    $(this).val(x.toString().replace(/,/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
Enter Amount:<input class="Amount" type="Amount" />
</form>