Skip to content

Instantly share code, notes, and snippets.

@michael-halim
Created May 9, 2023 02:49
Show Gist options
  • Save michael-halim/ee18cd8c3f7f96023f9a41a87a38d6ea to your computer and use it in GitHub Desktop.
Save michael-halim/ee18cd8c3f7f96023f9a41a87a38d6ea to your computer and use it in GitHub Desktop.
Add . Every 3 Numbers in Input Element using JQuery
# HTML
<input type="text" name="value" class="form-control" placeholder="Enter Value" required="" id="value">
# JQuery
$(function () {
$('body').on('keyup','input#value',function(){
let current_value = $(this).val().replace(/\D/g, '');
// Add a '.' after every 3 digits from the end of the input
current_value = current_value.replace(/(\d)(?=(\d{3})+$)/g, '$1.');
$(this).val(current_value);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment