<?php
// Правильные:
'84951234567', '+74951234567', '8-495-1-234-567',
' 8 (8122) 56-56-56', '8-911-1234567', '8 (911) 12 345 67',
'8-911 12 345 67', '8 (911) - 123 - 45 - 67', '+ 7 999 123 4567',
'8 ( 999 ) 1234567', '8 999 123 4567'
);
// Не правильные:
$incorrectNumbers = array( '02', '84951234567 позвать люсю', '849512345', '849512345678',
'8 (409) 123-123-123', '7900123467', '5005005001', '8888-8888-88',
'84951a234567', '8495123456a',
'+1 234 5678901', /* неверный код страны */
'+8 234 5678901', /* либо 8 либо +7 */
'7 234 5678901' /* нет + */
);
// Отредактированные
$correctNumbersEdited = array();
// Сначала идет +7 или 8, за ними ровно 10 цифр, между которыми может быть любое число скобок, минусов, пробелов
$regexp = "/^\\s?([+]\\s?[7]|8)\\W*[0-9]\\W*[0-9]\\W*[0-9]\\W*[0-9]\\W*[0-9]\\W*[0-9]\\W*[0-9]\\W*[0-9]\\W*[0-9]\\W*[0-9]$/u";
// Чистим
$regexpReplace1 = "/(\\D)/u";
$regexpReplace2 = "/^7/u";
foreach ($correctNumbers as $e) {
echo "Номер введен правильно\n";
$correctNumbersEdited[] = preg_replace($regexpReplace2, "8", $e);
} else {
echo "Номер введен НЕ правильно\n";
}
}
?>
PD9waHAKLy8g0J/RgNCw0LLQuNC70YzQvdGL0LU6IAokY29ycmVjdE51bWJlcnMgPSBhcnJheSggCiAgJzg0OTUxMjM0NTY3JywgICcrNzQ5NTEyMzQ1NjcnLCAnOC00OTUtMS0yMzQtNTY3JywgCiAgJyA4ICg4MTIyKSA1Ni01Ni01NicsICc4LTkxMS0xMjM0NTY3JywgJzggKDkxMSkgMTIgMzQ1IDY3JywgCiAgJzgtOTExIDEyIDM0NSA2NycsICc4ICg5MTEpIC0gMTIzIC0gNDUgLSA2NycsICcrIDcgOTk5IDEyMyA0NTY3JywgCiAgJzggKCA5OTkgKSAxMjM0NTY3JywgJzggOTk5IDEyMyA0NTY3JwopOwoKLy8g0J3QtSDQv9GA0LDQstC40Lv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