Skip to content

Commit

Permalink
Add comment and fix slice
Browse files Browse the repository at this point in the history
  • Loading branch information
idamand committed Nov 8, 2024
1 parent 777f83b commit 50bf34d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/utils/formatPhoneNumber.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/*
Format phone numbers:
Formatting for Norwegian numbers: +47 xxx xx xxx
Formatting for Swedish numbers: +46 xxx-xxx xx xx
*/

export default function formatPhoneNumber(phoneNumber: string) {
const firstDigitsOfPhoneNumber = phoneNumber.slice(0, 3);
let formattedPhoneNumber = ``;
if (firstDigitsOfPhoneNumber == "+47") {
formattedPhoneNumber = `+${phoneNumber.slice(1, 3)} ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(6, 8)} ${phoneNumber.slice(8)}`;
formattedPhoneNumber = `${phoneNumber.slice(0, 3)} ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(6, 8)} ${phoneNumber.slice(8)}`;
} else if (firstDigitsOfPhoneNumber == "+46") {
formattedPhoneNumber = `+${phoneNumber.slice(1, 3)} 0${phoneNumber.slice(3, 5)}-${phoneNumber.slice(5, 8)} ${phoneNumber.slice(8, 10)} ${phoneNumber.slice(10)}`;
formattedPhoneNumber = `${phoneNumber.slice(0, 3)} 0${phoneNumber.slice(3, 5)}-${phoneNumber.slice(5, 8)} ${phoneNumber.slice(8, 10)} ${phoneNumber.slice(10)}`;
} else {
formattedPhoneNumber = phoneNumber;
}
Expand Down

0 comments on commit 50bf34d

Please sign in to comment.