Skip to content

Instantly share code, notes, and snippets.

@hasibkamal
Last active December 31, 2016 06:17
Show Gist options
  • Save hasibkamal/4c3dbd28c53caf964ac44f6f55fabb12 to your computer and use it in GitHub Desktop.
Save hasibkamal/4c3dbd28c53caf964ac44f6f55fabb12 to your computer and use it in GitHub Desktop.
Comma Separated Number
function commaSeparateNumber(val)
{
while (/(\d+)(\d{3})/.test(val.toString()))
{
val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
}
return val;
}
var thisVal = commaSeparateNumber(this.value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment