Skip to content

Instantly share code, notes, and snippets.

@anova
Last active June 14, 2024 07:54
Show Gist options
  • Save anova/bfccdb910fb4ca07b482f38ea945282c to your computer and use it in GitHub Desktop.
Save anova/bfccdb910fb4ca07b482f38ea945282c to your computer and use it in GitHub Desktop.
Format phone number for Turkey (+90) and strip parantheses and spaces.
function () {
if (!document.querySelector('#telefon') || 0 === document.querySelector('#telefon').value.length) {
return null;
}
var phone = '+90' + document.querySelector('#telefon').value.replace(/[\(|\)|\s]/g,'');
//+905551234567 -> 13 karakter
if (13 < phone.length) {
return null;
}
return phone;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment