Skip to content

Instantly share code, notes, and snippets.

@belchior
Created April 4, 2018 20:55
Show Gist options
  • Save belchior/a4f215af18ee528f38dd6a7ad31ba98f to your computer and use it in GitHub Desktop.
Save belchior/a4f215af18ee528f38dd6a7ad31ba98f to your computer and use it in GitHub Desktop.
function formatBarcode(barcode) {
return barcode.replace(/(\d{0,5})(\d{0,5})(\d{0,5})(\d{0,6})(\d{0,5})(\d{0,6})(\d{0,1})(.*)/, '$1.$2 $3.$4 $5.$6 $7 $8');
}
@belchior
Copy link
Author

belchior commented Apr 4, 2018

usage

formatBarcode('43297415040000185441162571011125174900000006636')

> "43297.41504 00001.854411 62571.011125 1 74900000006636"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment