<?php
function numCheck($numArray) {
foreach ($numArray as $id => $number) {
$regexp = "/^\ ?((\+\ ?7)|8)\ ?(\(?\ ?\-?\d\ ?\)?){3,4}(\ ?\-?\ ?\d){6,7}$/";
echo "+ {$number} \n";
} else {
echo "- {$number} \n";
}
}
}
$correctNumbers = [
'8 ( 495 ) 1 - 2 - 3 - 4 - 5 - 6 - 7', '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 = [
'8 911 415 (16) (13)', '8 (((((((((((((((1938(((((2)((((21(((((21(((2', '8(((((((-------((((( ( --- ((((9(((1(((1)3------4----------5-----------6-----------7----((((8--------9)','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' /* нет + */
];
numCheck($correctNumbers);
numCheck($incorrectNumbers);
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiBudW1DaGVjaygkbnVtQXJyYXkpIHsKCWZvcmVhY2ggKCRudW1BcnJheSBhcyAkaWQgPT4gJG51bWJlcikgewoJCSRyZWdleHAgPSAiL15cID8oKFwrXCA/Nyl8OClcID8oXCg/XCA/XC0/XGRcID9cKT8pezMsNH0oXCA/XC0/XCA/XGQpezYsN30kLyI7CgkJaWYgKHByZWdfbWF0Y2goJHJlZ2V4cCwgJG51bWJlcikpIHsKCQkJZWNobyAiKyB7JG51bWJlcn0gXG4iOwoJCX0gZWxzZSB7CgkJCWVjaG8gIi0geyRudW1iZXJ9IFxuIjsKCQl9Cgl9Cn0KJGNvcnJlY3ROdW1iZXJzID0gWyAKICAnOCAoIDQ5NSApIDEgLSAyIC0gMyAtIDQg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