From ffaeb55113d34ef037206c8bdd45ba6bd01e14fa Mon Sep 17 00:00:00 2001 From: dani poni <459630@gmail.com> Date: Sat, 2 Apr 2016 17:04:44 +0200 Subject: [PATCH] Better ZIP code validation for German ZIP codes. Regex expression taken from: http://www.fadoe.de/blog/archives/262-Regulaerer-Ausdruck-fuer-Deutsche-Postleitzahlen.html --- docs/authors.rst | 1 + localflavor/de/forms.py | 7 ++----- tests/test_de.py | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/authors.rst b/docs/authors.rst index 387eb7c8b..dca22d37d 100644 --- a/docs/authors.rst +++ b/docs/authors.rst @@ -18,6 +18,7 @@ Authors * Bruno M. Custódio * Claude Paroz * Daniel Roschka +* Daniela Ponader * Douglas Miranda * Erik Romijn * Flavio Curella diff --git a/localflavor/de/forms.py b/localflavor/de/forms.py index 1d15a7281..dea66bc54 100644 --- a/localflavor/de/forms.py +++ b/localflavor/de/forms.py @@ -28,11 +28,8 @@ class DEZipCodeField(RegexField): } def __init__(self, max_length=None, min_length=None, *args, **kwargs): - super(DEZipCodeField, self).__init__(r'^\d{5}$', - max_length, - min_length, - *args, - **kwargs) + super(DEZipCodeField, self).__init__(r'^([0]{1}[1-9]{1}|[1-9]{1}[0-9]{1})[0-9]{3}$', + max_length, min_length, *args, **kwargs) class DEStateSelect(Select): diff --git a/tests/test_de.py b/tests/test_de.py index a7d9edf30..46fbd24ef 100644 --- a/tests/test_de.py +++ b/tests/test_de.py @@ -35,6 +35,7 @@ def test_DEZipCodeField(self): '99423': '99423', } invalid = { + '00000': error_format, ' 99423': error_format, } self.assertFieldOutput(DEZipCodeField, valid, invalid)