function my_formatter_default in Phone Number 6
Same name and namespace in other branches
- 7 includes/phone.my.inc \my_formatter_default()
Default formatter for international 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 113 - CCK Field for Malaysia phone numbers.
Code
function my_formatter_default($element) {
$item = $element['#item'];
// Display a global phone number with country code.
$cc = cck_phone_countrycodes($item['country_codes']);
// Format the phone number however you like, this is the default
foreach (_my_phone_rules() as $rule) {
// define regular expression
$regex = '/^
(' . $rule[0] . ') # area code
(\\d{3,4})
(\\d{4})
$/x';
$result = preg_match($regex, $item['number'], $matches);
if ($result) {
// output as +60A-BBB CCCC or +60A-BBBB CCCC
$phone = $cc['code'] . $matches[1] . '-' . $matches[2] . ' ' . $matches[3];
continue;
}
}
return $phone . $ext;
}