Skip to content

Instantly share code, notes, and snippets.

@amrikarisma
Forked from yudapc/Javascript Format NPWP
Created April 4, 2023 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amrikarisma/5365b7448eacc4f0ce4ba0a029815454 to your computer and use it in GitHub Desktop.
Save amrikarisma/5365b7448eacc4f0ce4ba0a029815454 to your computer and use it in GitHub Desktop.
Javascript Format NPWP. NPWP is ID tax each people of indonesian. Specificly in frontend need to format NPWP before render to user
//
// Javascript Format NPWP
//
function formatNpwp(value) {
if (typeof value === 'string') {
return value.replace(/(\d{2})(\d{3})(\d{3})(\d{1})(\d{3})(\d{3})/, '$1.$2.$3.$4-$5.$6');
}
}
console.log(formatNpwp('232323234444444'));
// Output 23.232.323.4-444.444
//
// Typescript Format NPWP
//
const npwpFormat = (nStr: string) => {
return nStr.replace(/(\d{2})(\d{3})(\d{3})(\d{1})(\d{3})(\d{3})/, '$1.$2.$3.$4-$5.$6');
};
console.log(formatNpwp('232323234444444'));
// Output 23.232.323.4-444.444
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment