You are here

function format_cr_phone_number in Phone 7

Same name and namespace in other branches
  1. 6 phone.cr.inc \format_cr_phone_number()

File

include/phone.cr.inc, line 51
CCK Field for Costa Rican phone numbers.

Code

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

  // define regular expression
  $regex = "/(00)?[\\s|-]?((\\+)?[\\s|-]?[0-9]{3})?[\\s|-]?([0-9]{2})[\\s|-]?([0-9]{2})[\\s|-]?([0-9]{2})[\\s|-]?([0-9]{2})[\\s|-]?/";

  // get digits of phone number

  //dprint_r($matches);
  preg_match($regex, $phonenumber, $matches);

  // construct eight-digit phone number

  //dprint_r($matches);
  $phonenumber = $matches[4] . '-' . $matches[5] . '-' . $matches[6] . '-' . $matches[7];
  if ($matches[2]) {
    if ($matches[1]) {
      $phonenumber = "+" . $matches[2] . " " . $phonenumber;
    }
    else {
      $phonenumber = $matches[2] . " " . $phonenumber;
    }
  }
  return $phonenumber;
}