Index: include/phone.es.inc =================================================================== --- include/phone.es.inc (revision 20) +++ include/phone.es.inc (revision 21) @@ -24,17 +24,17 @@ $phonenumber = trim($phonenumber); // 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}$/'; + + $regex = '/ + \D* # optional separator + (\+[0-9]{2})? # optional international code + \D* # optional separator + \d{3} # first number group + \D* # optional separator + \d{3} # second number group + \D* # optional separator + \d{3} # third number group + $/'; // return true if valid, false otherwise @@ -50,23 +50,23 @@ 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}$/'; + $regex = '/ + \D* # optional separator + (\+[0-9]{2})? # optional international code + \D* # optional separator + (\d{3}) # first number group + \D* # optional separator + (\d{3}) # second number group + \D* # optional separator + (\d{3}) # third number group + $/'; // get digits of phone number preg_match($regex, $phonenumber, $matches); // construct ten-digit phone number - $phonenumber = $matches[1] . ' ' . $matches[2] . ' ' . $matches[3]; + + $phonenumber = $matches[1] . ' ' . $matches[2] . ' ' . $matches[3] . ' ' . $matches[4] ; return $phonenumber; }