You are here

function my_formatter_local in Phone Number 6

Same name and namespace in other branches
  1. 7 includes/phone.my.inc \my_formatter_local()

Local formatter for local phone number.

Parameters

$element: $element['#item']['country_codes']: alpha-2 country code $element['#item']['number']: phone number

$error: The error message to shown to user. Available parameters to use in the error message are

  • "%countrycode": the alpha-2 CC
  • "%phone_input": the original number input by user (could be invalid)
  • "%max_length": allowed maximum length of the phone number

Return value

boolean TRUE if it is a valid phone number for that country, FALSE otherwise.

File

includes/phone.my.inc, line 156
CCK Field for Malaysia phone numbers.

Code

function my_formatter_local($element) {

  // Display a local phone number without country code.
  $phone = $element['#item']['number'];
  foreach (_my_phone_rules() as $rule) {

    // define regular expression
    $regex = '/^
      (' . $rule[0] . ')                   # area code
      (\\d{3,4})
      (\\d{4})
      $/x';
    $result = preg_match($regex, $phone, $matches);
    if ($result) {

      // output as 0A-BBB CCCC or 0A-BBBB CCCC
      $phone = '0' . $matches[1] . '-' . $matches[2] . ' ' . $matches[3];
      continue;
    }
  }
  return $phone;
}