You are here

function format_il_phone_number in Phone 6

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

Formatting for Israeli Phone Numbers. Based upon ITU-T E.123 (but let's not get too crazy)

Parameters

string $phonenumber:

Return value

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

File

./phone.il.inc, line 68
CCK Field for Isreali phone numbers.

Code

function format_il_phone_number($phonenumber) {
  $prefix = '';
  $extension = '';

  // strip old formatting chars
  $phonenumber = preg_replace('/[\\-() ]/', '', $phonenumber);

  /*
   * strip and save the +9726 prefix if found
   */
  if (preg_match('/^\\+972/', $phonenumber, $match)) {
    $prefix = '+972 ';
    $phonenumber = str_replace('+972', '', $phonenumber);
  }

  /*
   * 9 phones digit numbers
   * Eg. 03 9999 999
   */
  if (preg_match('/^([0-9]{2})([0-9]{4})([0-9]{3})$/', $phonenumber, $match)) {
    return $prefix . $match[1] . ' ' . $match[2] . ' ' . $match[3] . $extension;
  }

  /*
   * 10 digit numbers
   * Eg. 1800 999 999
   */
  if (preg_match('/^([0-9]{4})([0-9]{3})([0-9]{3})$/', $phonenumber, $match)) {
    return $prefix . $match[1] . ' ' . $match[2] . ' ' . $match[3] . $extension;
  }

  /*
   * cell phone
   * Eg. 054 9999 999
   */
  if (preg_match('/^([0-9]{3})([0-9]{4})([0-9]{3})$/', $phonenumber, $match)) {
    return $prefix . $match[1] . ' ' . $match[2] . ' ' . $match[3] . $extension;
  }

  // default
  return $prefix . $phonenumber . $extension;
}