Skip to content

Instantly share code, notes, and snippets.

@ideabrian
Created June 24, 2014 05:02
Show Gist options
  • Save ideabrian/a90f86ae42416e7c9836 to your computer and use it in GitHub Desktop.
Save ideabrian/a90f86ae42416e7c9836 to your computer and use it in GitHub Desktop.
Regex for inserting a comma in the correct place.
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