You are here

function format_cs_phone_number in Phone 7

Same name and namespace in other branches
  1. 6 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

include/phone.cs.inc, line 38
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;
}