function format_hu_phone_number in Phone 6
Same name and namespace in other branches
- 7 include/phone.hu.inc \format_hu_phone_number()
Convert a valid Hungarian phone number into standard (+36) ..... format
Parameters
$phonenumber must be a valid nine-digit number (with optional international prefix):
File
- ./
phone.hu.inc, line 48 - CCK Field for Hungarian phone numbers.
Code
function format_hu_phone_number($phonenumber, $field = FALSE) {
// define regular expression
$regex = "/\n \\D* # optional separator\n\t(?:\\+?36|06)? # country code\n (\\d\\d?) # area code\n \\D* # optional separator\n (\\d{3}) # second group\n \\D* # optional separator\n (\\d{3,4}) # third group\n \\D* # ignore trailing non-digits\n \$/x";
// get digits of phone number
preg_match($regex, $phonenumber, $matches);
// construct ten-digit phone number
$phonenumber = '+36 ' . $matches[1] . ' ' . $matches[2] . ' ' . $matches[3] . ' ' . $matches[4];
return $phonenumber;
}