From 219a79421745b90b2e8976b7a83c3435c337237f Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Sat, 25 Jun 2011 12:39:29 +0000 Subject: [PATCH] Fixed #16338 -- Fixed Austrian postal codes validation. Thanks Bernhard Essl for the report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16447 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/localflavor/at/forms.py | 4 ++-- docs/ref/contrib/localflavor.txt | 3 ++- tests/regressiontests/forms/localflavor/at.py | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/django/contrib/localflavor/at/forms.py b/django/contrib/localflavor/at/forms.py index 52721368e05..262641bf1f3 100644 --- a/django/contrib/localflavor/at/forms.py +++ b/django/contrib/localflavor/at/forms.py @@ -16,13 +16,13 @@ class ATZipCodeField(RegexField): """ A form field that validates its input is an Austrian postcode. - Accepts 4 digits. + Accepts 4 digits (first digit must be greater than 0). """ default_error_messages = { 'invalid': _('Enter a zip code in the format XXXX.'), } def __init__(self, max_length=None, min_length=None, *args, **kwargs): - super(ATZipCodeField, self).__init__(r'^\d{4}$', + super(ATZipCodeField, self).__init__(r'^[1-9]{1}\d{3}$', max_length, min_length, *args, **kwargs) class ATStateSelect(Select): diff --git a/docs/ref/contrib/localflavor.txt b/docs/ref/contrib/localflavor.txt index d4c9dca495f..1e565a58b1a 100644 --- a/docs/ref/contrib/localflavor.txt +++ b/docs/ref/contrib/localflavor.txt @@ -243,7 +243,8 @@ Austria (``at``) .. class:: at.forms.ATZipCodeField - A form field that validates its input as an Austrian zip code. + A form field that validates its input as an Austrian zip code, with the + format XXXX (first digit must be greater than 0). .. class:: at.forms.ATStateSelect diff --git a/tests/regressiontests/forms/localflavor/at.py b/tests/regressiontests/forms/localflavor/at.py index 3fa50ac4df7..11e0cd4ec1c 100644 --- a/tests/regressiontests/forms/localflavor/at.py +++ b/tests/regressiontests/forms/localflavor/at.py @@ -28,6 +28,8 @@ class ATLocalFlavorTests(LocalFlavorTestCase): '8020': '8020', } invalid = { + '0000' : error_format, + '0123' : error_format, '111222': error_format, 'eeffee': error_format, }