Skip to content

Instantly share code, notes, and snippets.

@jpcaparas
Created May 9, 2019 23:46
Show Gist options
  • Save jpcaparas/2821d4d677c6242c306ecd1f5a1299c4 to your computer and use it in GitHub Desktop.
Save jpcaparas/2821d4d677c6242c306ecd1f5a1299c4 to your computer and use it in GitHub Desktop.
JS: Sanitize amount
const sanitizeAmount = amount => {
return amount
.replace(/[^\d.]/g, '') // Remove non-numeric symbols
.replace(/\.(?!\d+$)/g, ''); // Remove excess "." symbols, and leave out the last "."
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment