diff --git a/README.txt b/README.txt index 841bd9b..65da5ba 100644 --- a/README.txt +++ b/README.txt @@ -40,6 +40,7 @@ Features: + Egypt, + South Africa, + Pakistan, + + Romania, and Canadian phone numbers and generic international phone numbers * Formating of phone numbers diff --git a/countries.txt b/countries.txt index 7b5ef0a..717592c 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 @@ -37,6 +38,7 @@ ph => Philippine pk => Pakistan pl => Poland pt => Portugal +ro => Romania ru => Russia se => Sweden sg => Singapore 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/include/phone.ro.inc b/include/phone.ro.inc new file mode 100644 index 0000000..84b6471 --- /dev/null +++ b/include/phone.ro.inc @@ -0,0 +1,37 @@ + '"%value" is not a valid Romanian mobile phone number', + ); +} + +/** + * Verifies that $phonenumber is valid + * + * @param string $phonenumber + * @return boolean Returns boolean FALSE if the phone number is not valid. + */ +function valid_ro_phone_number($phonenumber) { + // define regular expression + $regex = "/\b(\+|[0]{2})?(\d{3}|\d{4}|\d{5})[-. ]?(\d{4}|\d{3}|\d{2})[-. ]?(\d{3}|\d{4}|\d{2})[-. ]?(\d{3}|\d{4}|\d{2}|)\b/i"; + + // return true if valid, false otherwise + return (bool) preg_match($regex, $phonenumber); +} + +/** + * Formatting for Romanian Phone Numbers. + * + * @param string $phonenumber + * @return string Returns a string containting the phone number with some formatting. + */ +function format_ro_phone_number($phonenumber, $field) { + // @TODO + return $phonenumber; +} diff --git a/phone.module b/phone.module index 9be0fd0..ab061bd 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', @@ -43,9 +44,11 @@ function phone_countries($code = NULL) { 'jo' => 'Jordan', 'eg' => 'Egypt', 'pk' => 'Pakistan', + 'ro' => 'Romania', 'int' => 'International Phone Numbers per E.123', ); } + asort($countries); return ($code === NULL) ? $countries : (isset($countries[$code]) ? $countries[$code] : NULL); }