<?php
function verificationPhone($pattern, $telephoneNumber){
foreach($telephoneNumber as $value){
echo "{$value}\t-\tOK\n";
}else{
echo "{$value}\t-\tERROR\n";
}
}
}
// Правильные:
'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' /* нет + */
);
$pattern = "/^((\s*8\s*)|(\s*\+\s*7\s*))[\s-\(\) ]*\d[\s-\(\) ]*\d[\s-\(\) ]*\d[\s-\(\) ]*\d[\s-\(\) ]*\d[\s-\(\) ]*\d[\s-\(\) ]*\d[\s-\(\) ]*\d[\s-\(\) ]*\d[\s-\(\) ]*\d$/u";
verificationPhone($pattern, $correctNumbers);
echo "\n\n";
verificationPhone($pattern, $incorrectNumbers);
?>
PD9waHAKCWVycm9yX3JlcG9ydGluZygtMSk7CgltYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKCQoJZnVuY3Rpb24gdmVyaWZpY2F0aW9uUGhvbmUoJHBhdHRlcm4sICR0ZWxlcGhvbmVOdW1iZXIpewoJCWZvcmVhY2goJHRlbGVwaG9uZU51bWJlciBhcyAkdmFsdWUpewoJCQlpZihwcmVnX21hdGNoKCRwYXR0ZXJuLCAkdmFsdWUpID09PSAxKSB7CgkJCQllY2hvICJ7JHZhbHVlfVx0LVx0T0tcbiI7CgkJCX1lbHNlewoJCQkJZWNobyAieyR2YWx1ZX1cdC1cdEVSUk9SXG4iOwoJCQl9CgkJfQoJfQoJCgkvLyDQn9GA0LDQstC40LvRjNC90YvQtTogCgkkY29ycmVjdE51bW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