--- a/phone.fr.inc	2012-11-09 11:15:36.000000000 +0100
+++ b/phone.fr.inc	2012-11-19 16:04:46.434203000 +0100
@@ -5,12 +5,14 @@
  * CCK Field for French phone numbers.
  */
 
-define('PHONE_FR_REGEX', '/(\+33|0)([1-9]\d{8}|85\d{7}|87[0-57-9]\d{6})$/');
+define('PHONE_FR_REGEX', '/^((?:0(?:0|11)|\+)33(?:0)?|0)([1-9]\d{8}(#\d{3,4})?)$/');
+define('PHONE_FR_REGEX_NSN', '/^(([1-79])|(8\d{2}))(\d{2})(\d{2})(\d{2})(\d{2})?(#\d{3,4})?$/');
 
 function phone_fr_metadata() {
   // These strings are translated using t() on output.
   return array(
-    'error' => '"%value" is not a valid French phone number<br>French phone numbers should only contain numbers and spaces and be like 99 99 99 99 99',
+    'label' => 'Phone Numbers - France',
+    'error' => '"%value" is not a valid French phone number<br>French phone numbers should only contain numbers and spaces and be like 09 99 99 99 99',
   );
 }
 
@@ -24,7 +26,7 @@
  */
 function valid_fr_phone_number($phonenumber) {
 
-  //$phonenumber = trim($phonenumber);
+  $phonenumber = trim($phonenumber);
 
   $phonenumber  = str_replace(array(' ','-','(',')'), '', $phonenumber);
   return (bool) preg_match(PHONE_FR_REGEX, $phonenumber);
@@ -36,11 +38,32 @@
  * @param string $phonenumber
  * @return string Returns a string containting the phone number with some formatting.
  */
+ 
 function format_fr_phone_number($phonenumber, $field = FALSE) {
-  $phone  = str_replace(array(' ','-','(',')'), '', $phonenumber);
-  if (preg_match(PHONE_FR_REGEX, $phone, $matches) != 1) {
+
+  $phonenumber = trim($phonenumber);
+
+  $phone = str_replace(array(" ","-","(",")"), "", $phonenumber);
+
+  if (!preg_match(PHONE_FR_REGEX, $phone, $matches)) {
     return $phonenumber; // not a french phone number
+ } else {
+    $phoneprefix = $matches['1'];
+    $phonensn = $matches['2'];
+
+    if (preg_match(PHONE_FR_REGEX_NSN, $phonensn, $matchesnsn)) {
+      $phonensn = trim($matchesnsn['1'] . " " . $matchesnsn['4'] . " " . $matchesnsn['5'] . " " . $matchesnsn['6'] . " " . $matchesnsn['7'] . " " . $matchesnsn['8']);
+      if ($field['phone_country_code']) {
+        $phonenumber = "+33 " . " " . $phonensn;
+      } else {
+        if ($phoneprefix == "0") {
+          $phonenumber = "0" . $phonensn;
+        } else {
+          $phonenumber = "+33" . " " . $phonensn;
+        }
+      }
+    }
   }
 
-  return ($field && $field['phone_country_code'] ? '+33 ' : '0') . $matches[2];
+  return $phonenumber;
 }
