function format_za_phone_number in Phone 6
Same name and namespace in other branches
- 7 include/phone.za.inc \format_za_phone_number()
Convert a valid South African phone number into standard ... format
Parameters
$phonenumber must be a valid ... digit number (with optional international prefix):
File
- ./
phone.za.inc, line 39 - CCK Field for South African phone numbers.
Code
function format_za_phone_number($phonenumber, $field) {
// define regular expression
$regex = '/^((?:\\+27|27)|0)[ ]*((\\d{2})(-| )?(\\d{3})(-| )?(\\d{4})|(\\d{2})( |-)(\\d{7}))$/';
// get digits of phone number
preg_match($regex, $phonenumber, $matches);
/*
drupal_set_message('$matches[1] = ' . $matches[1], 'error');
drupal_set_message('$matches[2] = ' . $matches[2], 'error');
drupal_set_message('$matches[3] = ' . $matches[3], 'error');
drupal_set_message('$matches[4] = ' . $matches[4], 'error');
drupal_set_message('$matches[5] = ' . $matches[5], 'error');
drupal_set_message('$matches[6] = ' . $matches[6], 'error');
drupal_set_message('$matches[7] = ' . $matches[7], 'error');
drupal_set_message('$matches[8] = ' . $matches[8], 'error');
*/
if ($field['phone_country_code']) {
$phonenumber = '+27' . ' ' . $matches[3] . '-' . $matches[5] . '-' . $matches[7];
}
else {
$phonenumber = $matches[3] . '-' . $matches[5] . '-' . $matches[7];
}
return $phonenumber;
}