You are here

function format_fr_phone_number in Phone 5

Same name and namespace in other branches
  1. 6 phone.fr.inc \format_fr_phone_number()
  2. 7 include/phone.fr.inc \format_fr_phone_number()

Formatting for French Phone Numbers.

Parameters

string $phonenumber:

Return value

string Returns a string containting the phone number with some formatting.

File

./phone.fr.inc, line 30

Code

function format_fr_phone_number($phonenumber, $field) {

  //$phonenumber = trim($phonenumber);

  // do some formatting on the phone number

  //if doesn't start by '+' add it at the beginning and ins not empty
  if (!preg_match("/^(\\+){1}[0-9 ]*\$/i", $phonenumber) && !$phonenumber == '') {
    $phonenumber = '+' . $phonenumber;
  }
  if ($field['phone_country_code']) {

    //if french phone number, add the country code at the beginning
    if (!preg_match("/^(\\+){1}33[ ]*[0-9 ]*\$/i", $phonenumber) && !$phonenumber == '') {
      $phonenumber = str_replace("+", "+" . "33" . " ", $phonenumber);
    }
  }
  return $phonenumber;
}