'Phone Numbers - Panama', 'error' => '"%value" is not a valid Panamanian phone number!
Panamanian phone numbers should contain only numbers, spaces and dashes be like 9999-999, 9999 999 or 9999999 with an optional prefix of "+507" or "00507".', ); } /** * Verifies that $phonenumber is a valid nine-digit Panamanian phone number * * @param string $phonenumber * @return boolean Returns boolean FALSE if the phone number is not valid. */ function valid_pa_phone_number($phonenumber) { //$phonenumber = trim($phonenumber); // define regular expression // return true if valid, false otherwise return (bool) preg_match(PHONE_PA_REGEX, $phonenumber); } /** * Convert a valid Panamenian phone number into standard (+507) 260-4324 format * * @param $phonenumber must be a valid nine-digit number (with optional international prefix) * */ function format_pa_phone_number($phonenumber, $field = FALSE) { // get digits of phone number preg_match(PHONE_PA_REGEX, $phonenumber, $matches); if (preg_match(PHONE_PA_REGEX, $phonenumber, $matches) != 1) { return $phonenumber; // not a Panamanian phone number } $phonenumber = $matches[3] . '-' . $matches[4]; if (trim($matches[1]) != '') { $phonenumber = '+' . substr($matches[1], -4) . $phonenumber; } elseif ($field && isset($field['phone_country_code'])) { $phonenumber = '+507 ' . $phonenumber; } return $phonenumber; }