You are here

function format_cs_phone_number in Phone 6

Same name and namespace in other branches
  1. 7 include/phone.cs.inc \format_cs_phone_number()

Convert a valid Czech phone number into standard (+420) 999 999 999 format

Parameters

$phonenumber must be a valid nine-digit number (with optional international prefix):

File

./phone.cs.inc, line 39
CCK Field for Czech phone numbers.

Code

function format_cs_phone_number($phonenumber, $field) {

  // define regular expression
  $regex = '/^((?:\\+|00)420)? ?(\\d{3}) ?(\\d{3}) ?(\\d{3})$/';

  // get digits of phone number
  preg_match($regex, $phonenumber, $matches);
  if ($field['phone_country_code']) {
    $phonenumber = '+420' . ' ' . $matches[2] . ' ' . $matches[3] . ' ' . $matches[4];
  }
  else {
    $phonenumber = $matches[2] . ' ' . $matches[3] . ' ' . $matches[4];
  }
  return $phonenumber;
}