Hello,

I added the option of a German postcode field. I hope it works, and I think it could be used for Italy postcodes too!

CommentFileSizeAuthor
zipcode.ge_.inc_.txt1.01 KBBambusstock

Comments

thierry_gd’s picture

Status: Needs review » Fixed

taken into account in 6.2.7 version

Bambusstock’s picture

Status: Fixed » Needs review

I found a bug and fix him. Now just postcodes with one zero at the beginning are allowed!

This is the Code:

<?php
// $Id: zipcode.ge.inc,v 1.9 2010/04/02 16:32:02 thierrygd Exp $

// Copyright 2008 Thierry GUEGAN http://www.arvoriad.com
// German postcode added by Ferenc Züllich

/**
 * @file
 * CCK Field for German zipcodes.
 */

/**
 * Verification for German zipcodes.
 *
 * @param string $text
 * @return boolean Returns boolean FALSE if the zipcode is not valid.
 * On success, returns a string containting the zipcode with some formatting.
 */
function valid_ge_zipcode($zipcodestring) {

  $zipcodestring = trim($zipcodestring);
  if (!preg_match("/^[0-9]{1}[1-9]{1}[0-9]{3}$/i",$zipcodestring)) {
  	return FALSE;
  }
  //right now just do a quick check ==> has to be improved
  //need to check more precisely by doing a query on a zipcode table, ...
  else
  {
	return TRUE;
  }
}

/**
 * Formatting for zipcode.
 *
 * @param string $zipcodestring
 * @return string Returns a string containting the zipcode with some formatting.
 */
function format_ge_zipcode($zipcodestring) {

  $zipcodestring = trim($zipcodestring);
  //do some formatting
  return $zipcodestring;
}

thierry_gd’s picture

Status: Needs review » Fixed

Fix in 6.2.8 version

Bambusstock’s picture

I improve the verification again! Zipcodes like "10203" will be no longer false.

if (strlen($zipcodestring) == 5) {
    if (substr($zipcodestring, 0, 1) != '0') {
      if (!preg_match("#^[1-9]{1}[0-9]{4}$#i", $zipcodestring)) {
	  return FALSE;
	}
	else{
	  return TRUE;
	}
    }
    elseif (substr($zipcodestring, 0, 1) == '0') {
	if (!preg_match("#^[0-9]{1}[1-9]{1}[0-9]{3}$#i", $zipcodestring)) {
	  return FALSE;
	}
	else{
		return TRUE;
	}
    }
  }
  else{
	return FALSE;
  }
thierry_gd’s picture

Status: Fixed » Active
thierry_gd’s picture

Status: Active » Needs review

Did it a different way : could you perform some testing and tell me if you are OK with the results

thierry_gd’s picture

Taken into account in 6.2.9 version

thierry_gd’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.