Skip to content

Instantly share code, notes, and snippets.

@yuraloginoff
Created November 30, 2015 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuraloginoff/ccb861231b6ff9ebb0ea to your computer and use it in GitHub Desktop.
Save yuraloginoff/ccb861231b6ff9ebb0ea to your computer and use it in GitHub Desktop.
Format number in input
// Format number in input
function formatNumber(num) {
return ("" + num).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, function($1) { return $1 + " " });
}
$('.format-num').on('keyup', function () {
$(this).val( formatNumber(this.value.replace(/\s/g, '')) );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment