Last active
November 16, 2023 03:21
-
-
Save yudapc/4c94a02f71cbe102d5105a109d9f4499 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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
thank you