Index: www-lp/www/includes/functions/validations.php =================================================================== diff -u -r4 -r26 --- www-lp/www/includes/functions/validations.php (.../validations.php) (revision 4) +++ www-lp/www/includes/functions/validations.php (.../validations.php) (revision 26) @@ -220,4 +220,575 @@ return $intracom_array; } // <- TVAINT + +function tep_validate_phone($arg_phone) +{ + $ret = array(); + $method=""; # heuristic method used + $country_code=""; # country code, ex: +33 + $phone_no_cc=""; # phone without country code, ex: 0680997289 + + # suppression des caractères extra + # remplacement des O par des 0 + $phone = str_replace("O", "0", $arg_phone); + + # on va remplacer le + placé au tout début par 00 + $phone = preg_replace('/^\+/', "00", $phone); + + # on ne converve que les chiffres + $phone = preg_replace('/[^\d]/', '', $phone); + + # FRANCE METROPOLITAINE + # 10 chiffres qui commencent par 01,02,03,04,05,06,07 + if (preg_match('/^(0[1-7]\d{8})$/', $phone, $matches)) { + $country_code ="33"; + $phone_no_cc = $matches[1]; + $method = "france-10-chiffres"; + } + # 0033 ou 33 suivi de 9 chiffres qui commencent par 1,2,3,4,5,6,7 + else if (preg_match('/^(0033|33)([1-7]\d{8})$/', $phone, $matches)) { + $country_code ="33"; + $phone_no_cc = "0" . $matches[2]; + $method = "france-0033-ou-33-suivi-de-9-chiffres"; + } + # 0033 ou 33 suivi de 10 chiffres qui commencent par 01,02,03,04,05,06,07 + # invalide normalement, ici on devine + else if (preg_match('/^(0033|33)(0[1-7]\d{8})$/', $phone, $matches)) { + $country_code ="33"; + $phone_no_cc = $matches[2]; + $method = "bizarre-france-0033-ou-33-suivi-de-10-chiffres"; + } + # BELGIQUE + # 0032 ou 32 suivi + # d'un 4 suivi de 8 chiffres (mobile) + else if (preg_match('/^(0032|32)(4\d{8})$/', $phone, $matches)) { + $country_code ="32"; + $phone_no_cc = "0" . $matches[2]; + $method = "belgique-mobile-0032-ou-32-suivi-de-4-et-9-chiffres"; + } + # d'un indicatif régional sur 1 ou 2 chiffres et + # d'un numéro sur 6 ou 7 chiffres (fixe) + else if (preg_match('/^(0032|32)(\d{1,2}\d{6,7})$/', $phone, $matches)) { + $country_code ="32"; + $phone_no_cc = "0" . $matches[2]; + $method = "belgique-fixe-0032-ou-32-suivi-de-7-a-9-chiffres"; + } + # ALGERIE 00213 ou 213 suivi de 9 chiffres + else if (preg_match('/^(00213|213)(\d{9})$/', $phone, $matches)) { + $country_code ="213"; + $phone_no_cc = "0" . $matches[2]; + $method = "algerie-00213-ou-213-suivi-de-9-chiffres"; + } + # POLYNESIE 00689 ou 689 suivi de 8 chiffres + else if (preg_match('/^(00689|689)(\d{8})$/', $phone, $matches)) { + $country_code ="689"; + $phone_no_cc = $matches[2]; + $method = "polynesie-00689-ou-689-suivi-de-8-chiffres"; + } + # il manque le service (fixe=40, mobile=87, spéciaux=89), on va considérer que le numéro est un mobile + else if (preg_match('/^(00689|689)(\d{6})$/', $phone, $matches)) { + $country_code ="689"; + $phone_no_cc = "87" . $matches[2]; + $method = "bizarre-polynesie-00689-ou-689-suivi-de-6-chiffres"; + } + # ALLEMAGNE + # 0049 ou 49 suivi + # de 0 puis 9 ou 10 chiffres + elseif (preg_match('/^(0049|49)([1-9]\d{9,10})$/', $phone, $matches)){ + $country_code = "49"; + $phone_no_cc = "0" . $matches[1]; + $method = "allemagne-0049-ou-49-suivi-de-9-ou-10-chiffres"; + } + elseif (preg_match('/^(0049|49)(0\d{9,10})$/', $phone, $matches)){ + $country_code = "49"; + $phone_no_cc = $matches[1]; + $method = "bizarre-allemagne-0049-ou-49-suivi-de-0-et-9-ou-10-chiffres"; + } + # SUISSE + # 0041 ou 41 suivi de 9 chiffres + elseif (preg_match('/^(0041|41)(\d{9})$/', $phone, $matches)){ + $country_code = "49"; + $phone_no_cc = "0" . $matches[1]; + $method = "suisse-0041-ou-41-suivi-de-9-chiffres"; + } + elseif (preg_match('/^(0041|41)(0\d{9})$/', $phone, $matches)){ + $country_code = "49"; + $phone_no_cc = $matches[1]; + $method = "bizarre-suisse-0041-ou-41-suivi-0-et-de-9-chiffres"; + } + # LUXEMBOURG + # 00352 ou 352 suivi de 9 chiffres + elseif (preg_match('/^(00352|352)(\d{4,9})$/', $phone, $matches)){ + $country_code = "352"; + $phone_no_cc = $matches[2]; + $method = "luxembourg-00352-ou-352-suivi-de-4-a-9-chiffres"; + } + # PORTUGAL + elseif (preg_match('/^(00351|351)(\d{9})$/', $phone, $matches)){ + $country_code = "351"; + $phone_no_cc = $matches[1]; + $method = "portugal-00351-ou-351-suivi-10-chiffres-portugal"; + } + # DANEMARK + elseif (preg_match('/^(0045|45)(\d{8})$/', $phone, $matches)){ + $country_code = "45"; + $phone_no_cc = $matches[1]; + $method = "danemark-0045-ou-45-suivi-de-8-chiffres"; + } + elseif (strpos($arg_phone, '(0)') !== false) { + if (preg_match('/^(\d{2})0(\d{9})$/', $phone, $matches)){ + $country_code = $matches[1]; + if ($country_code == "32"){ + $phone_no_cc = $matches[1] . $matches[2]; + $method = "numero-international-belgique-9-chiffres"; + } + elseif ($country_code == "33"){ + $country_code ="33"; + $phone_no_cc = "0" . $matches[2]; + $method = "numero-international-france-9-chiffres"; + } + elseif ($country_code == "41"){ + $country_code ="41"; + $phone_no_cc = "0" . $matches[2]; + $method = "numero-international-suisse-9-chiffres"; + } + } + elseif (preg_match('/^(\d{2})0(\d{8})$/', $phone, $matches)){ + $country_code = $matches[1]; + if ($country_code == "32"){ + $phone_no_cc = $matches[1] . $matches[2]; + $method = "numero-international-belgique-8-chiffres"; + } + } + elseif (preg_match('/^(\d{2})0(\d{10})$/', $phone, $matches)){ + $country_code = $matches[1]; + if ($country_code == "49"){ + $phone_no_cc = $matches[1] . $matches[2]; + $method = "numero-international-allemagne-10-chiffres"; + } + } + elseif (preg_match('/^(\d{2})0(\d{11})$/', $phone, $matches)){ + $country_code = $matches[1]; + if ($country_code == "49"){ + $phone_no_cc = $matches[1] . $matches[2]; + $method = "numero-international-allemagne-11-chiffres"; + } + } + elseif (preg_match('/^00(\d{2})0(\d{9})$/', $phone, $matches)){ + $country_code = $matches[1]; + if ($country_code == "32"){ + $phone_no_cc = $matches[1] . $matches[2]; + $method = "00-numero-international-belgique-9-chiffres"; + } + elseif ($country_code == "33"){ + $phone_no_cc = "0" . $matches[2]; + $method = "00-numero-international-france-9-chiffres"; + } + elseif ($country_code == "41"){ + $phone_no_cc = "0" . $matches[2]; + $method = "00-numero-international-suisse-9-chiffres"; + } + } + elseif (preg_match('/^00(\d{2})0(\d{8})$/', $phone, $matches)){ + $country_code = $matches[1]; + if ($country_code == "32"){ + $phone_no_cc = $matches[1] . $matches[2]; + $method = "00-numero-international-belgique-8-chiffres"; + } + } + elseif (strpos($arg_phone, '(0)') !== false) { + if (preg_match('/^00(\d{3})0(\d{9})$/', $phone, $matches)){ + $country_code = $matches[1]; + if ($country_code == "594"){ + $phone_no_cc = "0" . $matches[2]; + $method = "numero-international-guyane"; + } + elseif ($country_code == "33"){ + $phone_no_cc = "0" . $matches[2]; + $method = "numero-international-france"; + } + } + } + } + elseif (strpos($arg_phone, '( 0 )') !== false) { + if (preg_match('/^(\d{2})0(\d{9})$/', $phone, $matches)){ + $country_code = $matches[1]; + if ($country_code == "32"){ + $phone_no_cc = $matches[1] . $matches[2]; + $method = "00-espace-entre-(-0-)-numero-international-belgique-9-chiffres"; + } + } + } + elseif (preg_match('/^(\d)\1+$/', $phone)){ + $country_code = ""; + $phone_no_cc = ""; + $method = "meme-chiffre-repete"; + } + elseif(preg_match('/[A-Za-z]/', $phone)) { + $country_code = ""; + $phone_no_cc = ""; + $method = "numero-avec-lettre"; + } + elseif (!preg_match('/^[\p{L}\d\+]+$/u', $phone)) { + $country_code = ""; + $phone_no_cc = ""; + $method = "numero-avec-caractere-$phone-"; + } + elseif (preg_match('/^0496(\d{6})$/', $phone, $matches)){ + $country_code = "32"; + $phone_no_cc = "0496". $matches[1]; + $method = "0496-6-chiffres-mobile-belgique"; + } + elseif(preg_match('/^0032(\d{8})$/', $phone, $matches)){ + $country_code = "32"; + $phone_no_cc = $matches[1]; + $method = "0032-8-chiffres-belgique"; + } + elseif(preg_match('/^0032(\d{10})$/', $phone, $matches)){ + $country_code = "32"; + $phone_no_cc = $matches[1]; + $method = "0032-10-chiffres-belgique"; + } + elseif(preg_match('/^0039(\d{10})$/', $phone, $matches)){ + $country_code = "39"; + $phone_no_cc = $matches[1]; + $method = "0039-10-chiffres-allemagne"; + } + elseif(preg_match('/^0041(\d{9})$/', $phone, $matches)){ + $country_code = "41"; + $phone_no_cc = $matches[1]; + $method = "0041-9-chiffres-suisse"; + } + elseif (preg_match('/^0\d{10,}$/', $phone)) { + $country_code = ""; + $phone_no_cc = ""; + $method = "num-francais-debut-0-invalide-car-plus-de-10-chiffres"; + } + elseif (preg_match('/^0\d{9}/', $phone, $matches)){ + $country_code = "33"; + $phone_no_cc = $matches[0]; + $method = ""; + } + elseif (preg_match('/^0\d{8}/', $phone, $matches)){ + $country_code = ""; + $phone_no_cc = ""; + $method = "numero-commencant-par-0-suivi-8-chiffres"; + } + elseif (preg_match('/^41(\d{9})$/', $phone, $matches)){ + $country_code = "41"; + $phone_no_cc = "41" . $matches[1]; + $method = "41-suivi-9-chiffres-mobile-suisse"; + } + elseif (preg_match('/^41(\d{10})$/', $phone, $matches)){ + $country_code = "41"; + $phone_no_cc = "41" . $matches[1]; + $method = "41-suivi-10-chiffres-mobile-suisse"; + } + elseif (preg_match('/^34(\d{9})$/', $phone, $matches)){ + $country_code = "34"; + $phone_no_cc = "34" . $matches[1]; + $method = "34-suivi-9-chiffres-espagne"; + } + elseif (preg_match('/^31(\d{9})$/', $phone, $matches)){ + $country_code = "31"; + $phone_no_cc = "31" . $matches[1]; + $method = "31-suivi-9-chiffres-pays-bas"; + } + elseif (preg_match('/^49(\d{10})$/', $phone, $matches)){ + $country_code = "49"; + $phone_no_cc = "49" . $matches[1]; + $method = "49-suivi-10-chiffres-allemagne"; + } + elseif (preg_match('/^351(\d{10})$/', $phone, $matches)){ + $country_code = "351"; + $phone_no_cc = "351" . $matches[1]; + $method = "351-suivi-10-chiffres-portugal"; + } + elseif (preg_match('/^49(\d{11})$/', $phone, $matches)){ + $country_code = "49"; + $phone_no_cc = "49" . $matches[1]; + $method = "49-suivi-11-chiffres-allemagne"; + } + // Vérification pour un indicatif à 2 chiffres + elseif (preg_match('/^00(\d{2})(\d{9,10})$/', $phone, $matches)) { + if ((int)$matches[1] >= 10 && (int)$matches[1] <= 99) { // Vérification pour 2 chiffres + $country_code = $matches[1]; + $phone_no_cc = "0" . $matches[2]; + $method = "raw-avec-00-2-chiffres"; + } + } + + // Vérification pour un indicatif à 3 chiffres + elseif (preg_match('/^00(\d{3})(\d{6,9})$/', $phone, $matches)) { + if ((int)$matches[1] >= 100 && (int)$matches[1] <= 999) { // Vérification pour 3 chiffres + $country_code = $matches[1]; + $phone_no_cc = "0" . $matches[2]; + $method = "raw-avec-00-3-chiffres"; + } + } + elseif(preg_match('/^32(\d{9})$/', $phone, $matches)){ + $country_code = "32"; + $phone_no_cc = $country_code . $matches[1]; + $method = "32-suivi-9-chiffres-belgique"; + } + elseif(preg_match('/^33(\d{9})$/', $phone, $matches)){ + $country_code = "33"; + $phone_no_cc = "0" . $matches[1]; + $method = "33-suivi-9-chiffres-france"; + } + elseif(preg_match('/^39(\d{9})$/', $phone, $matches)){ + $country_code = "39"; + $phone_no_cc = $country_code . $matches[1]; + $method = "39-suivi-9-chiffres-italie"; + } + elseif(preg_match('/^39(\d{10})$/', $phone, $matches)){ + $country_code = "39"; + $phone_no_cc = $country_code . $matches[1]; + $method = "39-suivi-10-chiffres-italie"; + } + elseif (preg_match('/^(\d{3})(\d{9})$/', $phone, $matches)){ + $country_code = $matches[1]; + if ($country_code == '221'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-senegal-suivi-9-chiffres"; + } + elseif($country_code == '352'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-luxembourg-suivi-9-chiffres"; + } + elseif($country_code == '590'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-guadeloupe-suivi-9-chiffres"; + } + elseif($country_code == '262'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-ile-reunion-suivi-9-chiffres"; + } + elseif($country_code == '385'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-croatie-suivi-9-chiffres"; + } + elseif($country_code == '351'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-portugal-suivi-9-chiffres"; + } + } + elseif (preg_match('/^(\d{3})(\d{8})$/', $phone, $matches)){ + $country_code = $matches[1]; + if ($country_code == '352'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-luxembourg-suivi-8-chiffres"; + } + elseif ($country_code == '225'){ + $phone_no_cc = $country_code .$matches[2]; + $method = "raw-pour-cote-ivoire-suivi-8-chiffres"; + } + elseif ($country_code == '213'){ + $phone_no_cc = $country_code .$matches[2]; + $method = "raw-pour-algerie-suivi-8-chiffres"; + } + elseif ($country_code == '212'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-maroc-suivi-8-chiffres"; + } + elseif ($country_code == '223'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-mali-suivi-8-chiffres"; + } + elseif ($country_code == '689'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-polynesie-francaise-suivi-8-chiffres"; + } + } + elseif ( preg_match('/^(\d{3})(\d{6,8})$/', $phone, $matches)) + { + $country_code = $matches[1]; + if ($matches[1] == '689') { + $phone_no_cc = $matches[2]; + $method = "raw-pour-polynesie"; + } + elseif ($matches[1] == '687'){ + $phone_no_cc = $matches[2]; + $method = "raw-pour-nouvelle-caledonie"; + } + elseif ($matches[1] == '508'){ + $phone_no_cc = $matches[1] . $matches[2]; + $method = "raw-pour-st-pierre-miquelon"; + } + elseif ($matches[1] == '047'){ + $country_code = "32"; + $phone_no_cc = $matches[1] . $matches[2]; + $method = "mobile-belgique"; + } + elseif ($matches[1] == '473'){ + $country_code = "1473"; + $phone_no_cc = $matches[1] . $matches[2]; + $method = "caraibes"; + } + elseif ($matches[1] == '691'){ + $phone_no_cc = $matches[2]; + $method = "raw-pour-micronesie"; + } + elseif ($matches[1] == '675'){ + $phone_no_cc = $matches[2]; + $method = "raw-pour-nouvelle-guinee"; + } + elseif ($country_code == '632'){ + $phone_no_cc = $matches[2]; + $method = "raw-pour-philippines"; + } + elseif ($country_code == '352'){ + $phone_no_cc = $matches[2]; + $method = "raw-pour-luxembourg"; + } + elseif ($country_code == '221'){ + $phone_no_cc = $matches[2]; + $method = "raw-pour-senegal"; + } + else{ + $country_code = ""; + $phone_no_cc = ""; + $method = ""; + } + } + elseif (preg_match('/^(\d{3})(\d{6,8})$/', $phone, $matches)) { + $country_code = $matches[1]; + $phone_no_cc = "0" . $matches[2]; + $method = "raw-pour-3-chiffres-suivi-de-6-a-8-chiffres"; + } + elseif (preg_match('/^(\d{1})(\d{9})$/', $phone, $matches)) { + $country_code = $matches[1]; + $phone_no_cc = "0" . $matches[2]; + $method = "raw-avec-pour-1-chiffre"; + } + elseif (preg_match('/^(\d{2})(\d{9})$/', $phone, $matches)) { + $country_code = $matches[1]; + $phone_no_cc = "0" . $matches[2]; + $method = "raw-pour-2-chiffres"; + if ($country_code == '33'){ + $phone_no_cc = "0" . $matches[2]; + $method = "raw-avec-pour-france"; + } + } + elseif (preg_match('/^(\d{3})(\d{6,9})$/', $phone, $matches)) { + $country_code = $matches[1]; + $phone_no_cc = "0" . $matches[2]; + $method = "raw-pour-3-chiffres"; + if ($country_code == '514'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-canada"; + } + elseif ($country_code == '380'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-ukraine"; + } + } + elseif (preg_match('/^(\d{3})(\d{7})$/', $phone, $matches)) { + $country_code = $matches[1]; + $phone_no_cc = "0" . $matches[2]; + $method = ""; + } + elseif (preg_match('/^(\d{3})(\d{9})$/', $phone, $matches)) { + $country_code = $matches[1]; + $phone_no_cc = "0" . $matches[2]; + if ($country_code == '352'){ + $phone_no_cc = $country_code . $matches[2]; + $method = "raw-pour-luxembourg"; + } + } + elseif ( preg_match('/^07(\d{7})$/', $phone, $matches)) + { + $country_code = "689"; + $phone_no_cc = $country_code . $matches[1]; + $method = "mobile-polynesie-francaise"; + } + elseif (preg_match('/^063(\d{6})$/', $phone, $matches)){ + $country_code = "32"; + $phone_no_cc = "063". $matches[1]; + $method = "063-6-chiffres-fixe-belgique"; + } + elseif ( preg_match('/^001(\d{10})$/', $phone, $matches)) + { + $country_code = $matches[1]; + $phone_no_cc = $matches[2]; + $method = "raw-avec-001"; + } + elseif (preg_match('/^0\d{6,8}$/', $phone)) { + $country_code = ""; + $phone_no_cc = ""; + $method = "num-francais-debut-0-invalides-car-moins-de-10-chiffres"; + } + # nnnnnnnnnn : 10 chiffres décimaux + elseif ( preg_match('/^(\d{10})$/', $phone, $matches)) + { + $phone_no_cc = $matches[1]; + $prefix = substr($phone, 0, 4); + if ($prefix == '0690'){ + $country_code = '590'; + $method = "commence-par-0690"; + } + elseif ($prefix == '0694'){ + $country_code = '594'; + $method = "commence-par-0694"; + } + elseif ($prefix == '0696'){ + $country_code = '596'; + $method = "commence-par-0696"; + } + elseif ($prefix == '0692' or $prefix == '0693'){ + $country_code = '262'; + $method = "commence-par-0692-ou-0693"; + } + } + elseif (preg_match('/^06\d{11,}$/', $phone, $matches)) + { + $country_code = ""; + $phone_no_cc = ""; + $method = "trop-de-numero-pour-un-06"; + } + elseif(strlen($phone) == 20){ + $first_ten_digits = substr($phone, 0, 10); + $country_code = "33"; + $phone_no_cc = $first_ten_digits; + $method = "premier-num-tel"; + } + elseif(strlen($phone) <= 6){ + $country_code = ""; + $phone_no_cc = ""; + $method = "num-tel-inf-ou-egal-a-6"; + } + elseif (preg_match('/^0\d{10,}$/', $phone)){ + $country_code = "33"; + $phone_no_cc = $phone; + $method = "num-francais-debut-0-invalide-sup-ou-egal-a-10"; + } + elseif(preg_match('/^0\d{10}$/', $phone)) { + $country_code = "33"; + $phone_no_cc = $phone; + $method = "num-francais-debut-0-invalide-egal-a-10"; + } + else{ + $country_code = ""; + $phone_no_cc = ""; + $method = ""; + } + + $ret['method'] = $method; + $ret['country_code'] = $country_code; + $ret['phone'] = $phone_no_cc; + $ret['valid'] = $ret['country_code'] != ""; + return $ret; +} + +function tep_is_valid_number($data, $max_digit_count) +{ + // Vérifie que la variable n'est pas null^M + if ($data !== null) { + // Vérifie que la variable est un nombre et qu'elle contient entre 1 et 3 chiffres + if (is_numeric($data) && strlen((string)$data) >= 1 && strlen((string)$data) <= $max_digit_count) { + return true; // La variable est valide + } + } + return false; // La variable n'est pas valide +} ?>