function format_nl_phone_number in Phone 6
Same name and namespace in other branches
- 7 include/phone.nl.inc \format_nl_phone_number()
Formatting for Dutch Phone Numbers into standard area-phonenumber or with extra country code +31 international format
Parameters
string $phonenumber:
Return value
string Returns a string containting the phone number with some formatting.
File
- ./
phone.nl.inc, line 61 - CCK Field for Dutch phone numbers.
Code
function format_nl_phone_number($phonenumber, $field) {
$areacode = $localnumber = '';
// Mobile number
if (preg_match('/([0]{1}[6]{1}[-\\s]+[1-9]{1}[\\s]*([0-9]{1}[\\s]*){7})/', $phonenumber)) {
preg_match('/([0]{1}[6]{1})[-\\s]+([1-9]{1}[\\s]*([0-9]{1}[\\s]*){7})/', $phonenumber, $matches);
}
// Phonenumber with 4 digit area code
if (preg_match('/([0]{1}[1-9]{1}[0-9]{2}[-\\s]+[1-9]{1}[\\s]*([0-9]{1}[\\s]*){5})/', $phonenumber)) {
preg_match('/([0]{1}[1-9]{1}[0-9]{2})[-\\s]+([1-9]{1}[\\s]*([0-9]{1}[\\s]*){5})/', $phonenumber, $matches);
}
// Phonenumber with 3 digit area code
if (preg_match('/([0]{1}[1-9]{1}[0-9]{1}[-\\s]+[1-9]{1}[\\s]*([0-9]{1}[\\s]*){6})/', $phonenumber)) {
preg_match('/([0]{1}[1-9]{1}[0-9]{1})[-\\s]+([1-9]{1}[\\s]*([0-9]{1}[\\s]*){6})/', $phonenumber, $matches);
}
$areacode = $matches[1];
$localnumber = preg_replace('/ /', '', $matches[2]);
$phonenumber = $areacode . '-' . $localnumber;
// Add Country code if needed
if ($field['phone_country_code']) {
$areacode = preg_replace('/^0/', '', $areacode);
$phonenumber = '+31-' . $areacode . '-' . $localnumber;
}
return $phonenumber;
}