ZF-8612: Zend_Validate_PostCode and UK PostCodes

Issue Type: Improvement Created: 2009-12-22T06:49:21.000+0000 Last Updated: 2010-07-26T08:03:09.000+0000 Status: Resolved Fix version(s): - 1.10.3 (01/Apr/10)

Reporter: Lloyd Watkin (lloydwatkin) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate

Related issues: Attachments:


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.


Posted by Lloyd Watkin (lloydwatkin) on 2009-12-22T06:50:36.000+0000

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

Posted by Thomas Weidner (thomas) on 2009-12-22T13:58:14.000+0000

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

Posted by Thomas Weidner (thomas) on 2009-12-23T13:13:54.000+0000

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

Posted by Steven Bakhtiari (stevebakh) on 2010-02-02T03:10:55.000+0000

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.

Posted by Lloyd Watkin (lloydwatkin) on 2010-02-02T03:25:17.000+0000

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.

Posted by Thomas Weidner (thomas) on 2010-02-02T05:46:04.000+0000

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

Posted by Thomas Weidner (thomas) on 2010-03-14T03:22:03.000+0000

Implemented with r21487 Changed detection needs updated CLDR.

Posted by Ceri Williams (cezmunsta) on 2010-07-26T02:00:45.000+0000

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) }


Posted by Lloyd Watkin (lloydwatkin) on 2010-07-26T02:34:07.000+0000

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

Posted by Ceri Williams (cezmunsta) on 2010-07-26T02:49:03.000+0000

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

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-07-26T08:03:08.000+0000

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

Have you found an issue?

See the Overview section for more details.


© 2006-2022 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.