? canadian.patch
Index: zipcode.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/zipcode/zipcode.module,v
retrieving revision 1.7
diff -u -p -r1.7 zipcode.module
--- zipcode.module 26 Dec 2006 11:48:55 -0000 1.7
+++ zipcode.module 24 Apr 2007 06:03:12 -0000
@@ -198,7 +198,7 @@ function zipcode_widget($op, &$node, $fi
form_set_error($field['field_name'],t('"%value" is not a valid french zipcode
Zipcodes should only contains 4 or 5 numbers',array('%value' => $item['value'])));
}
if ($field['type'] == 'ca_zipcode' && !valid_ca_zipcode($item['value'])) {
- form_set_error($field['field_name'],t('"%value" is not a canadian valid zipcode
Zipcodes should be like Z5Z-5Z5 orZ5Z5Z5 ...',array('%value' => $item['value'])));
+ form_set_error($field['field_name'],t('"%value" is not a valid Canadian postal code, it should be like A1A 1A1 or A1A1A1',array('%value' => $item['value'])));
}
if ($field['type'] == 'us_zipcode' && !valid_us_zipcode($item['value'])) {
form_set_error($field['field_name'],t('"%value" is not a valid us zipcode
Zipcodes should be like 99999 or 99999-9999 ...',array('%value' => $item['value'])));
@@ -239,10 +239,10 @@ function valid_ca_zipcode($zipcodestring
$zipcodestring = trim($zipcodestring);
- if (!preg_match("/^\D{1}\d{1}\D{1}\-?\d{1}\D{1}\d{1}/i",$zipcodestring)) {
+ if (!preg_match("/^\D{1}\d{1}\D{1}\ ?\d{1}\D{1}\d{1}/i",$zipcodestring)) {
return false;
}
- //Z5Z-5Z5 orZ5Z5Z5
+ //Z5Z 5Z5 or Z5Z5Z5
else
{
return true;
@@ -295,6 +295,19 @@ function format_fr_zipcode($zipcodestrin
function format_ca_zipcode($zipcodestring) {
$zipcodestring = trim($zipcodestring);
+
+ $zipcodestring = strtoupper($zipcodestring);
+
+ if (strlen($zipcodestring) == 6) {
+ $zipcodestring = substr($zipcodestring, 0, 3) . ' ' . substr($zipcodestring, 3, 3);
+ }
+
+ return $zipcodestring;
+}
+
+function format_us_zipcode($zipcodestring) {
+
+ $zipcodestring = trim($zipcodestring);
//do some formatting
return $zipcodestring;
}
@@ -312,4 +325,4 @@ function format_nl_zipcode($zipcodestrin
//do some formatting: make letters upper case and put space between numbers and letters
$zipcodestring = preg_replace("/(\d{4})\s*(\w{2})/","$1 $2",strtoupper($zipcodestring));
return $zipcodestring;
-}
\ No newline at end of file
+}