diff --git a/countries.txt b/countries.txt index 7b5ef0a..a7a3592 100644 --- a/countries.txt +++ b/countries.txt @@ -1,5 +1,6 @@ ad => Andorran -ar => Argentinan +ar => Argentinan +at => Austria au => Australia bd => Bangladesh be => Belgium diff --git a/include/phone.at.inc b/include/phone.at.inc new file mode 100644 index 0000000..35a92a1 --- /dev/null +++ b/include/phone.at.inc @@ -0,0 +1,51 @@ + '"%value" is not a valid Austrian phone number.
Austrian phone numbers should only contain numbers and spaces and be like 07582 99 999', + ); +} + +/** + * Verification for private/standr Austrian Phone Numbers (E.164/2002). + * According to https://en.wikipedia.org/wiki/Telephone_numbers_in_Austria + * + * @param string $phonenumber + * @return boolean Returns FALSE if the phone number is not valid. + */ +function valid_at_phone_number($phonenumber) { + $phonenumber = str_replace(array(' ','-','.','/','(',')'), '', $phonenumber); + $match = array(); + $result = (bool) preg_match(PHONE_AT_REGEX, $phonenumber, $match); + return $result; +} + +/** + * Formatting for Austrian Phone Numbers. + * + * @param string $phonenumber + * @return string Returns a string containing the phone number with some formatting. + */ +function format_at_phone_number($phonenumber, $field = FALSE) { + $phone = str_replace(array(' ','-','.','/','(',')'), '', $phonenumber); + $matches = array(); + if (preg_match(PHONE_AT_REGEX, $phone, $matches) != 1) { + return $phonenumber; // not a Austrian phone number + } + + $prefix_length = ((bool) preg_match('/(6|720|8)\d*$/', $matches[2])) ? 4 : 5; + + $value = ($field && $field['phone_country_code'] ? '+43 (0) ' : '0') . + substr($matches[2], 0, $prefix_length - 1). + ' ' . substr($matches[2], $prefix_length - 1); + + return $value; +} diff --git a/phone.module b/phone.module index 9be0fd0..aa0ffd9 100644 --- a/phone.module +++ b/phone.module @@ -16,6 +16,7 @@ function phone_countries($code = NULL) { 'it' => 'Italy', 'el' => 'Greece', 'ch' => 'Switzerland', + 'at' => 'Austria', 'ca' => 'US & Canada', 'cr' => 'Costa Rica', 'pa' => 'Panama', @@ -46,6 +47,7 @@ function phone_countries($code = NULL) { 'int' => 'International Phone Numbers per E.123', ); } + asort($countries); return ($code === NULL) ? $countries : (isset($countries[$code]) ? $countries[$code] : NULL); }