ZF-8612: Zend_Validate_PostCode and UK PostCodes


UK postcodes tend to have the format:

AA1 1ZZ A1 2ZZ A11 2ZZ AA11 2ZZ

When testing we have found that the latest 1.10-alpha version does not allow for this space in the formatting. Minor issue as developer can strip whitespace for validation and reformat for output, but it would be much better to have it accept the format that the public use.

Matthew Vivian has created a fix for this which we'll upload once we get relevant docs signed / etc.


Please contact us as we're not sure how to submit the fix (regex change required)

Please note that it is not good behaviour to change code without asking the maintainer/developer (which is me in this case). ;-)

You should additionally note, when you've took a look at 1.10, that the regex is provided by CLDR, which is used within the I18n core and created by Unicode.

This means on the other hand that problems on the underlaying CLDR must be issues at Unicode ( as ZF is not allowed to change CLDR and deliver such a version.

In such a case, that non-conform postcodes are wanted (even if they are common there must be a reason why the english maintainers at unicode dont match such a format), you should use a filter on the input before validation

Closing as won't fix. Read the previous comment for how to proceed.

This is frustrating - British postcodes do typically contain a space. Please see and…

I guess we need to pester cldr regarding this issue then...

I know I should probably post a separate bug report for this, but pretty much all of the default error messages in the validator use terrible English and could do with being updated. Error messages don't even include the invalid value, because the author forgot to add $this->_setValue($value) in the isValid method.

I have just posted a 'bug' report to unicode with your links attached:

We ended up creating our own validator with the 'correct' regex, the change is fairly trivial.

Hopefully unicode will update their standards ASAP for the next release of ZF.

Reopened for changing the message Not agreed for changing CLDR within ZF

Implemented with r21487 Changed detection needs updated CLDR.

Is this supposed to be fixed as I am having problems with 1.10.5?

php > set_include_path('.:/usr/local/zend/share/ZendFramework/library'); php > require 'Zend/Loader/Autoloader.php'; php > Zend_Loader_Autoloader::getInstance(); php > $postcode1 = 'G12 8AD'; php > $postcode2 = 'G128AD'; php > $validator = new Zend_Validate_PostCode('en_GB'); php > var_dump(array($validator->isValid($postcode1), $validator->isValid($postcode2))); array(2) { [0]=> bool(false) [1]=> bool(true) }


The issue won't be fixed as it isn't ZF that's wrong.

The issue is with unicode CLDR, see the ticket here,

It seems the guys who maintain the UK standards haven't been around in while (as far as I can see) so the standard/format isn't being updated.

In the end we resorted to either:

  • Adding our own validator which extends postcode validator and strips whitespace
  • Stripping whitespace and using a view helper for output

Sorry, somehow I missed the original post with the link to the bug report. Thanks for clarifying Lloyd.

I may be stating the obvious here, but of course anybody is free to contribute to CLDR (besides ZF of course), I suppose.