Created
May 9, 2023 02:49
-
-
Save michael-halim/ee18cd8c3f7f96023f9a41a87a38d6ea to your computer and use it in GitHub Desktop.
Add . Every 3 Numbers in Input Element using JQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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