Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #9259 -- Fixed a validation error for Spanish identity card num…

…bers.

Patch from Marc Garcia.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@9129 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7cec38b0762622541ddf3904e6363362cb3fba23 1 parent cff78c6
Malcolm Tredinnick authored October 05, 2008
6  django/contrib/localflavor/es/forms.py
@@ -76,8 +76,8 @@ def __init__(self, only_nif=False, *args, **kwargs):
76 76
         self.cif_control = 'JABCDEFGHI'
77 77
         self.cif_types = 'ABCDEFGHKLMNPQS'
78 78
         self.nie_types = 'XT'
79  
-        super(ESIdentityCardNumberField, self).__init__(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types + self.cif_types.lower() + self.nie_types.lower(), self.nif_control + self.nif_control.lower()),
80  
-                max_length=None, min_length=None,
  79
+        id_card_re = re.compile(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control + self.cif_control), re.IGNORECASE)
  80
+        super(ESIdentityCardNumberField, self).__init__(id_card_re, max_length=None, min_length=None,
81 81
                 error_message=self.default_error_messages['invalid%s' % (self.only_nif and '_only_nif' or '')],
82 82
                 *args, **kwargs)
83 83
 
@@ -88,7 +88,7 @@ def clean(self, value):
88 88
         nif_get_checksum = lambda d: self.nif_control[int(d)%23]
89 89
 
90 90
         value = value.upper().replace(' ', '').replace('-', '')
91  
-        m = re.match(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control), value)
  91
+        m = re.match(r'^([%s]?)[ -]?(\d+)[ -]?([%s]?)$' % (self.cif_types + self.nie_types, self.nif_control + self.cif_control), value)
92 92
         letter1, number, letter2 = m.groups()
93 93
 
94 94
         if not letter1 and letter2:
2  tests/regressiontests/forms/localflavor/es.py
@@ -157,6 +157,8 @@
157 157
 'X3287690R'
158 158
 >>> f.clean('t-03287690r')
159 159
 'T03287690R'
  160
+>>> f.clean('P2907500I')
  161
+'P2907500I'
160 162
 >>> f.clean('X-03287690')
161 163
 Traceback (most recent call last):
162 164
 ...

0 notes on commit 7cec38b

Please sign in to comment.
Something went wrong with that request. Please try again.