Last active
October 21, 2021 17:55
-
-
Save choyan/d32263a638360eb67ab5bb57096c62ae to your computer and use it in GitHub Desktop.
Türk cep telefonu numarası formatı. Turkish Phone Code format. (Javascript)
This file contains hidden or 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
// Inspired from this answer by maerics https://stackoverflow.com/a/8358141/1648286 | |
function phoneNumberFormatView(phoneNumberString) { | |
let cleaned = ('' + phoneNumberString).replace(/\D/g, ''); | |
let match = cleaned.match(/^(90|)?(\d{3})(\d{3})(\d{2})(\d{2})$/); | |
if (match) { | |
let intlCode = (match[1] ? '+90 ' : ''); | |
return [intlCode, match[2], ' ', match[3], ' ', match[4], ' ', match[5]].join(''); | |
} | |
return null; | |
} |
This file contains hidden or 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
export function phoneNumberFormatView(phoneNumberString: string): string { | |
let cleaned = ('' + phoneNumberString).replace(/\D/g, ''); | |
let match = cleaned.match(/^(90|)?(\d{3})(\d{3})(\d{2})(\d{2})$/); | |
if (match) { | |
let intlCode = (match[1] ? '+90 ' : ''); | |
return [intlCode, match[2], ' ', match[3], ' ', match[4], ' ', match[5]].join(''); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output