3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function validatePhone( $phone, &$errsData = null, &$mainData = null ) { $res = false; if( isset( $phone ) && $phone != null ) { $phone = preg_replace("/[^0-9]/","", $phone ); //удаляем всё кроме цифр if ($phone && preg_match('/^(8|7|\+7)[0-9]{10}$/', $phone )) { // if( substr( $phone, 0, 1) == '8' ) $phone[0] = '7'; @$mainData['phone'] = $phone; $res = $phone; } else { $errsData['phone']['error_msg'] = "Укажите номер в формате +7 000 000 00 00"; } } else { $errsData['phone']['error_msg'] = "Укажите Ваш номер телефона"; } return $res; } var_dump ( validatePhone('+79278918933') ); ?>
based on tQQd1
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.6
string(11) "79278918933"