Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/phone/README.txt,v
retrieving revision 1.19
diff -u -r1.19 README.txt
--- README.txt	8 Mar 2009 00:04:26 -0000	1.19
+++ README.txt	27 Mar 2009 22:24:51 -0000
@@ -20,6 +20,7 @@
 	+ Czech, 
 	+ Hungarian,
 	+ Costa Rican, 
+  + Brazilian,
 	+ US 
 	and Canadian phone numbers 
 * Formating of phone numbers 
Index: phone.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/phone/phone.module,v
retrieving revision 1.23
diff -u -r1.23 phone.module
--- phone.module	8 Mar 2009 00:04:26 -0000	1.23
+++ phone.module	27 Mar 2009 21:42:58 -0000
@@ -38,7 +38,8 @@
     'au_phone' => array('label' => t('Australian Phone Numbers')),
     'cs_phone' => array('label' => t('Czech Phone Numbers')), 
     'hu_phone' => array('label' => t('Hungarian Phone Numbers')),
-    'nl_phone' => array('label' => t('Dutch Phone Numbers'))    
+    'nl_phone' => array('label' => t('Dutch Phone Numbers')),    
+    'br_phone' => array('label' => t('Brazilian Phone Numbers')),
    );
 }
 
@@ -134,8 +135,9 @@
        || $field['type'] == 'es_phone'
        || $field['type'] == 'au_phone'
        || $field['type'] == 'cs_phone'
-       || $field['type'] == 'hu_phone'       
-       || $field['type'] == 'nl_phone'              
+       || $field['type'] == 'hu_phone'         
+       || $field['type'] == 'nl_phone'     
+       || $field['type'] == 'br_phone'              
        ) { 
       	$columns = array(
         	'value' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
@@ -217,7 +219,10 @@
           }                  
           if ($field['type'] == 'nl_phone' && !valid_phone_number('nl', $item['value'])) {
             form_set_error($field['field_name'], t('"%value" is not a valid Dutch phone number!<br>Dutch phone numbers should contain only numbers and spaces and - and be like 099-9999999 with an optional prefix of "+31".', array('%value' => $item['value'])));
-          }            
+          }                      
+          if ($field['type'] == 'br_phone' && !valid_phone_number('br', $item['value'])) {
+            form_set_error($field['field_name'], t('"%value" is not a valid Brazilian phone number!<br>Brazilian phone numbers should contain only numbers and spaces and - and be like 099 9999-9999 or 99 9999-9999 with an optional prefix of "+55".', array('%value' => $item['value'])));
+          }        
         }
       }
       break;
@@ -258,7 +263,10 @@
           }  
           if ($field['type'] == 'nl_phone') {
             $node_field[$delta]['value'] = format_phone_number('nl', $node_field[$delta]['value'], $field);
-          }            
+          }       
+          if ($field['type'] == 'br_phone') {
+            $node_field[$delta]['value'] = format_phone_number('br', $node_field[$delta]['value'], $field);
+          }          
         }
       }
       break;
@@ -359,7 +367,8 @@
       			'au_phone',
       			'cs_phone', 
       			'hu_phone',
-      			'nl_phone'      			
+      			'nl_phone',
+      			'br_phone'       			
       			),
       'multiple values' => CONTENT_HANDLE_CORE,		
     ),
@@ -437,7 +446,8 @@
       			'au_phone',
       			'cs_phone',
       			'hu_phone',
-      			'nl_phone'      			
+      			'nl_phone',
+      			'br_phone'       			
       			),
       'multiple values' => CONTENT_HANDLE_CORE,
       'callbacks' => array(
@@ -645,7 +655,8 @@
   	|| $countrycode == 'au'
   	|| $countrycode == 'cs'  	
   	|| $countrycode == 'hu' 
-  	|| $countrycode == 'nl'   	
+  	|| $countrycode == 'nl'  
+  	|| $countrycode == 'br'  	
   	) { 
 	
         //drupal_set_message('langue = ' . $countrycode, 'error');
@@ -688,7 +699,8 @@
   	|| $countrycode == 'au'
    	|| $countrycode == 'cs' 	
    	|| $countrycode == 'hu' 	   	
-   	|| $countrycode == 'nl' 	   	   	
+   	|| $countrycode == 'nl' 	    	
+   	|| $countrycode == 'br' 	  	   	
   	) { 
 	
         //drupal_set_message('langue = ' . $countrycode, 'error');       
--- phone.br.inc
+++ phone.br.inc
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * @file
+ * CCK Field for Brazilian phone numbers.
+ * (based on CCK Field for French phone numbers.)
+ */
+
+define('PHONE_BR_REGEX', "/(55|0)?(\d{2})([1-9]\d{3})(\d{4})$/");
+
+/**  
+ * Verification for Brazilian Phone Numbers.  
+ *
+ * @param string $phonenumber
+ * @return boolean Returns boolean FALSE if the phone number is not valid. 
+ */
+function valid_br_phone_number($phonenumber) {
+
+  //$phonenumber = trim($phonenumber);
+
+  $phonenumber  = str_replace(array(' ','-','+','(',')'), '', $phonenumber);
+  return (bool) preg_match(PHONE_BR_REGEX, $phonenumber);
+}
+
+/**
+ * Formatting for Brazilian Phone Numbers.  
+ *
+ * @param string $phonenumber
+ * @return string Returns a string containting the phone number with some formatting.
+ */
+function format_br_phone_number($phonenumber, $field = FALSE) {
+  $phone  = str_replace(array(' ','-','(',')'), '', $phonenumber);
+  if (preg_match(PHONE_BR_REGEX, $phone, $matches) != 1) {
+    return $phonenumber; // this is possible?
+  }
+  $formatedphone = '';
+  if ($field && $field['phone_country_code']) {
+    $formatedphone .= '+55 ';
+  }
+  $formatedphone .= '(' . $matches[2] . ')';
+  $formatedphone .= ' ' . $matches[3] . '-';
+  $formatedphone .= '' . $matches[4];
+
+  return $formatedphone;
+}


