function format_au_phone_number in Phone 6
Same name and namespace in other branches
- 7 include/phone.au.inc \format_au_phone_number()
Formatting for Australian 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.au.inc, line 220 - CCK Field for Australian phone numbers.
Code
function format_au_phone_number($phonenumber, $field = FALSE) {
$prefix = '';
$extension = '';
// strip old formatting chars
$phonenumber = preg_replace('/[\\-() ]/', '', $phonenumber);
/*
* strip and save the +61 prefix if found
*/
if (preg_match('/^\\+61/', $phonenumber, $match)) {
$prefix = '+61 ';
$phonenumber = str_replace('+61', '', $phonenumber);
}
/*
* strip and save the extension (x9999) postfix if found
*/
if (preg_match('/(x[0-9]+)$/', $phonenumber, $match)) {
$extension = ' (' . $match[1] . ')';
$phonenumber = preg_replace('/x[0-9]+$/', '', $phonenumber);
}
/*
* geographic numbers and UPT
* Eg. (02) 9999 9999 or +61 (2) 9999 9999
*/
if (preg_match('/^(0{0,1}[23578])([0-9]{4})([0-9]{4})$/', $phonenumber, $match)) {
return $prefix . '(' . $match[1] . ') ' . $match[2] . ' ' . $match[3] . $extension;
}
/*
* mobile numbers
* Eg. 0423 999 999 or +61 423 999 999
*/
if (preg_match('/^(0{0,1}4[0-9]{2})([0-9]{3})([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;
}
/*
* 9 digit satellite or dialup data numbers
* Eg. 1471 99999
*/
if (preg_match('/^(14[0-9]{2}|1983)([0-9]{5})$/', $phonenumber, $match)) {
return $prefix . $match[1] . ' ' . $match[2] . $extension;
}
/*
* 6 digit numbers
* Eg. 13 99 99
*/
if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})$/', $phonenumber, $match)) {
return $prefix . $match[1] . ' ' . $match[2] . ' ' . $match[3] . $extension;
}
// default
return $prefix . $phonenumber . $extension;
}