Last active
October 15, 2021 15:32
-
-
Save stnc/4ab24bb620bcef35ea502ad6c1854e85 to your computer and use it in GitHub Desktop.
php turkey phone number validator (regex)
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
<?php | |
function turkcell_validator($str) | |
{ | |
$regex = '/^(\+?12)?(9053\d{1}|7[1-9]\d{1})\d{7}$/'; | |
preg_match_all($regex, $str, $matches, PREG_SET_ORDER, 0); | |
if (is_array($matches) && count($matches) > 0) { | |
return "var"; | |
} else { | |
return "yok"; | |
} | |
} | |
function vodafone_validator($str) | |
{ | |
$regex = '/^(\+?12)?(9054\d{1}|7[1-9]\d{1})\d{7}$/'; | |
preg_match_all($regex, $str, $matches, PREG_SET_ORDER, 0); | |
if (is_array($matches) && count($matches) > 0) { | |
return "var"; | |
} else { | |
return "yok"; | |
} | |
} | |
function avea_validator1($str) | |
{ | |
$regex = '/^(\+?12)?(9050\d{1}|7[1-9]\d{1})\d{7}$/'; | |
preg_match_all($regex, $str, $matches, PREG_SET_ORDER, 0); | |
print_r($matches); | |
if (is_array($matches) && count($matches) > 0) { | |
return "var"; | |
} else { | |
return "yok"; | |
} | |
} | |
function all_mobile_sms_validator($str) | |
{ | |
$sonuc = array(); | |
$sonuc[0] = avea_validator1("9050161596795"); | |
$sonuc[1] = vodafone_validator("905486159679"); | |
$sonuc[2] = turkcell_validator("905386159679"); | |
print_r($sonuc); | |
/* sonuc[0]=avea_validator1("0945016159679"); | |
$sonuc[1]=vodafone_validator("0945486159679"); | |
$sonuc[2]=turkcell_validator("0945386159679");*/ | |
if (in_array("var", $sonuc)) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
$numara = "095071179024"; | |
print_r(all_mobile_sms_validator($numara)); | |
//// other validator | |
$numara = "507 117 9024"; | |
//print_r(all_mobile_sms_validator($numara)); | |
if ($numara == "") { | |
echo 'numara bulunamadı'; | |
} else { | |
$numaram = str_replace(" ", "", $numara); | |
$numarakarakter = strlen($numaram); | |
if ($numarakarakter == 10) { | |
$chr_control = substr($numaram, 0, 1); | |
if ($chr_control == '5') { | |
$numaram = '90'.$numaram; | |
} //burada else koyup log yapmak gerek | |
} else if ($numarakarakter == 11) { | |
//burası ok sorun yok | |
$numaram = '9' . ($numaram);; | |
} elseif ($numarakarakter == 12) { | |
$chr_control = substr($numaram, 0, 1); | |
if ($chr_control == '9') { | |
$numaram = $numaram; | |
} //burada else koyup log yapmak gerek | |
} | |
} | |
echo $numaram; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment