Created
June 24, 2014 05:02
-
-
Save ideabrian/a90f86ae42416e7c9836 to your computer and use it in GitHub Desktop.
Regex for inserting a comma in the correct place.
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
var value = 1000; | |
var newValue = value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); | |
console.log(newValue); // "1,000" | |
regex found in HTML 5 In Action (Manning Publications) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment