I found that the regular expression is not working correctly on file phone.za.inc
/**
* Convert a valid South African phone number into standard ... format
*
* @param $phonenumber must be a valid ... digit number (with optional international prefix)
*
*/
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);
if ($field['phone_country_code']) {
$phonenumber = '+27' . ' ' . $matches[2] .'-'. $matches[3] .'-'. $matches[4];
}
else {
$phonenumber = $matches[2] .'-'. $matches[3] .'-'. $matches[4];
}
return $phonenumber;
}
which causes this part:
$phonenumber = $matches[2] .'-'. $matches[3] .'-'. $matches[4];
to only save "--" as phone number.
I currently bypassed the regular expression by doing this:
/**
* Convert a valid South African phone number into standard ... format
*
* @param $phonenumber must be a valid ... digit number (with optional international prefix)
*
*/
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);
if ($field['phone_country_code']) {
$phonenumber = '+27' . $phonenumber;
}
else {
$phonenumber = $phonenumber;
}
return $phonenumber;
}
I know this is not the correct way; but it now saves the data to the database.
Please will someone have a look and implement the correct regular expression.
Thanks in advance.
JCB
Comments
Comment #1
ckngI think you make a mistake with the project.
Moved to Phone (CCK).
Comment #2
avpadernoI am closing this issue, since it is for a Drupal version that now is not supported.
Please re-open it if the issue is also relevant for other project branches that require a supported Drupal version.