Last active
January 11, 2023 15:21
-
-
Save abdullahpazarbasi/d9cbf8223d35566255a4b468d18931dc to your computer and use it in GitHub Desktop.
Türkiye Telefon Numarası Regular Expression (Regex) Pattern PCRE
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
<?php | |
$sPattern = '/^(?:(?:\+90|0090|0)[ ]?)?(?:(?<ac>21[26]|22[2468]|23[26]|24[268]|25[268]|26[246]|27[246]|28[2468]|31[28]|32[2468]|33[28]|34[2468]|35[2468]|36[2468]|37[02468]|38[02468]|392|41[246]|42[2468]|43[2468]|44[26]|45[2468]|46[246]47[2468]|48[2468]|50[1567]|51[02]|52[27]|5[34]\d|55[1234569]|56[124]|59[246]|800|811|822|850|8[89]8|900)|\((?P<ac>\g<ac>)\))[ -]*(?<sn1>\d{3})[ -]*(?<sn2>\d{2})[ -]*(?<sn3>\d{2})$/J'; | |
// | |
//$sSubject = '5554443322'; | |
$sSubject = '(555)-444-33-22'; | |
// | |
$aMatches = []; | |
if (preg_match($sPattern, $sSubject, $aMatches)) { | |
echo '(' . $aMatches['ac'] . ') ' . $aMatches['sn1'] . ' ' . $aMatches['sn2'] . ' ' . $aMatches['sn3']; // (555) 444 33 22 | |
} | |
else { | |
echo 'oops!'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment