You are here

function format_jo_phone_number in Phone 7

Same name and namespace in other branches
  1. 6 phone.jo.inc \format_jo_phone_number()

Formatting for Jordanian Phone Numbers.

Parameters

string $phonenumber:

Return value

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

File

include/phone.jo.inc, line 89
This plugin is contributed by Untitled Web http://untitledstudios.com @author Rashad Majali <rashad.612@gmail.com> http://drupal.org/user/319686

Code

function format_jo_phone_number($phonenumber, $field = FALSE) {
  $phonenumber = trim($phonenumber);
  $regex = "/(^(\\+962|00962|962|0)[-\\s]{0,1}[7]{1}[7-9]{1}[0-9]{7}\$) | (^(\\+962|00962|962|0)[-\\s]{0,1}[2-6][-\\s]{0,1}[0-9]{7}\$)/x";
  preg_match($regex, $phonenumber, $matches);
  $phonenumber = preg_replace('/^(\\+962|00962|962|0)|[-\\s]/', '', $matches[0]);
  return '+962' . $phonenumber;
}