-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add formatting to phone numbers * Refactor function * Add comment and fix slice
- Loading branch information
Showing
4 changed files
with
27 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
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(0, 3)} ${phoneNumber.slice(3, 6)} ${phoneNumber.slice(6, 8)} ${phoneNumber.slice(8)}`; | ||
} else if (firstDigitsOfPhoneNumber == "+46") { | ||
formattedPhoneNumber = `${phoneNumber.slice(0, 3)} 0${phoneNumber.slice(3, 5)}-${phoneNumber.slice(5, 8)} ${phoneNumber.slice(8, 10)} ${phoneNumber.slice(10)}`; | ||
} else { | ||
formattedPhoneNumber = phoneNumber; | ||
} | ||
return formattedPhoneNumber; | ||
} |