function format_es_phone_number in Phone 6
Same name and namespace in other branches
- 5 phone.es.inc \format_es_phone_number()
- 7 include/phone.es.inc \format_es_phone_number()
Convert a valid Spanish phone number into standard (+34) 916 555 777 format
Parameters
$phonenumber must be a valid nine-digit number (with optional international prefix):
File
- ./
phone.es.inc, line 51 - CCK Field for Spanish phone numbers.
Code
function format_es_phone_number($phonenumber, $field = FALSE) {
// define regular expression
//$regex = "/
// \D* # optional separator
// ([69]\d{2}) # first group of numbers
// \D* # optional separator
// (\d{3}) # second group
// \D* # optional separator
// (\d{3}) # third group
// \D* # ignore trailing non-digits
// $/x";
$regex = '/^[0-9]{2,3}-? ?[0-9]{6,7}$/';
// get digits of phone number
preg_match($regex, $phonenumber, $matches);
// construct ten-digit phone number
$phonenumber = $matches[1] . ' ' . $matches[2] . ' ' . $matches[3];
return $phonenumber;
}