Created
November 30, 2015 16:37
-
-
Save yuraloginoff/ccb861231b6ff9ebb0ea to your computer and use it in GitHub Desktop.
Format number in input
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
// 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