You are here

function format_ru_phone_number in Phone 7

Same name and namespace in other branches
  1. 5 phone.ru.inc \format_ru_phone_number()
  2. 6 phone.ru.inc \format_ru_phone_number()

Convert a valid Russian phone number into standard +7 (495) 567-53-09 or +7 (444xx) 67-53-09 or mobile 8 910 414-56-90 format

Parameters

$phonenumber must be a valid ten-digit number (with optional extension):

File

include/phone.ru.inc, line 50
CCK Field for Russian phone numbers.

Code

function format_ru_phone_number($phonenumber, $field = FALSE) {

  // define regular expression
  $regex = "/\n    ^\\D*          # ignore non-digits\n    ([78])?       # an optional 78\n    \\D*           # optional separator\n    (\\d{3,5})  \t  # area code 3-5 digit\n    \\D*           # optional separator\n    (\\d{1,3})  \t  # capture 3-digit prefix\n    \\D*           # optional separator\n    (\\d{2})       # 2-digit line number\n    \\D*           # optional separator\n    (\\d{2})       # 2-digit line number\n    \\D*           # ignore trailing non-digits\n  /x";

  // get digits of phone number
  preg_match($regex, $phonenumber, $matches);

  // construct ten-digit phone number
  $phonenumber = $matches[1] . ' (' . $matches[2] . ') ' . $matches[3] . ' - ' . $matches[4] . ' - ' . $matches[5];
  return $phonenumber;
}