You are here

function format_es_phone_number in Phone 7

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

Convert a valid Spanish phone number into standard (+34) 916 555 777 format

Parameters

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

File

include/phone.es.inc, line 50
CCK Field for Spanish phone numbers.

Code

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

  // define regular expression

  //$regex = "/

  //  \D*           # optional separator
  //  ([69]\d{2})   # first group of numbers
  //  \D*           # optional separator
  //  (\d{3})       # second group
  //  \D*           # optional separator
  //  (\d{3})       # third group
  //  \D*           # ignore trailing non-digits
  //  $/x";
  $regex = '/^[0-9]{2,3}-? ?[0-9]{6,7}$/';

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

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