Ticket #17591: us_ssnfield_fix_v2.patch

File us_ssnfield_fix_v2.patch, 66.2 KB (added by anonymous, 12 years ago)
  • tests/regressiontests/localflavor/us/tests.py

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
    <+>from __future__ import absolute_import\n\nfrom django.contrib.localflavor.us.forms import (USZipCodeField,\n    USPhoneNumberField, USStateField, USStateSelect,\n    USSocialSecurityNumberField)\nfrom django.test import SimpleTestCase\n\nfrom .forms import USPlaceForm\n\n\nclass USLocalFlavorTests(SimpleTestCase):\n\n    def setUp(self):\n        self.form = USPlaceForm({'state':'GA', 'state_req':'NC', 'postal_code': 'GA', 'name':'impossible'})\n\n    def test_get_display_methods(self):\n        \"\"\"Test that the get_*_display() methods are added to the model instances.\"\"\"\n        place = self.form.save()\n        self.assertEqual(place.get_state_display(), 'Georgia')\n        self.assertEqual(place.get_state_req_display(), 'North Carolina')\n\n    def test_required(self):\n        \"\"\"Test that required USStateFields throw appropriate errors.\"\"\"\n        form = USPlaceForm({'state':'GA', 'name':'Place in GA'})\n        self.assertFalse(form.is_valid())\n        self.assertEqual(form.errors['state_req'], [u'This field is required.'])\n\n    def test_field_blank_option(self):\n        \"\"\"Test that the empty option is there.\"\"\"\n        state_select_html = \"\"\"\\\n<select name=\"state\" id=\"id_state\">\n<option value=\"\">---------</option>\n<option value=\"AL\">Alabama</option>\n<option value=\"AK\">Alaska</option>\n<option value=\"AS\">American Samoa</option>\n<option value=\"AZ\">Arizona</option>\n<option value=\"AR\">Arkansas</option>\n<option value=\"AA\">Armed Forces Americas</option>\n<option value=\"AE\">Armed Forces Europe</option>\n<option value=\"AP\">Armed Forces Pacific</option>\n<option value=\"CA\">California</option>\n<option value=\"CO\">Colorado</option>\n<option value=\"CT\">Connecticut</option>\n<option value=\"DE\">Delaware</option>\n<option value=\"DC\">District of Columbia</option>\n<option value=\"FL\">Florida</option>\n<option value=\"GA\" selected=\"selected\">Georgia</option>\n<option value=\"GU\">Guam</option>\n<option value=\"HI\">Hawaii</option>\n<option value=\"ID\">Idaho</option>\n<option value=\"IL\">Illinois</option>\n<option value=\"IN\">Indiana</option>\n<option value=\"IA\">Iowa</option>\n<option value=\"KS\">Kansas</option>\n<option value=\"KY\">Kentucky</option>\n<option value=\"LA\">Louisiana</option>\n<option value=\"ME\">Maine</option>\n<option value=\"MD\">Maryland</option>\n<option value=\"MA\">Massachusetts</option>\n<option value=\"MI\">Michigan</option>\n<option value=\"MN\">Minnesota</option>\n<option value=\"MS\">Mississippi</option>\n<option value=\"MO\">Missouri</option>\n<option value=\"MT\">Montana</option>\n<option value=\"NE\">Nebraska</option>\n<option value=\"NV\">Nevada</option>\n<option value=\"NH\">New Hampshire</option>\n<option value=\"NJ\">New Jersey</option>\n<option value=\"NM\">New Mexico</option>\n<option value=\"NY\">New York</option>\n<option value=\"NC\">North Carolina</option>\n<option value=\"ND\">North Dakota</option>\n<option value=\"MP\">Northern Mariana Islands</option>\n<option value=\"OH\">Ohio</option>\n<option value=\"OK\">Oklahoma</option>\n<option value=\"OR\">Oregon</option>\n<option value=\"PA\">Pennsylvania</option>\n<option value=\"PR\">Puerto Rico</option>\n<option value=\"RI\">Rhode Island</option>\n<option value=\"SC\">South Carolina</option>\n<option value=\"SD\">South Dakota</option>\n<option value=\"TN\">Tennessee</option>\n<option value=\"TX\">Texas</option>\n<option value=\"UT\">Utah</option>\n<option value=\"VT\">Vermont</option>\n<option value=\"VI\">Virgin Islands</option>\n<option value=\"VA\">Virginia</option>\n<option value=\"WA\">Washington</option>\n<option value=\"WV\">West Virginia</option>\n<option value=\"WI\">Wisconsin</option>\n<option value=\"WY\">Wyoming</option>\n</select>\"\"\"\n        self.assertEqual(str(self.form['state']), state_select_html)\n\n    def test_full_postal_code_list(self):\n        \"\"\"Test that the full USPS code field is really the full list.\"\"\"\n        usps_select_html = \"\"\"\\\n<select name=\"postal_code\" id=\"id_postal_code\">\n<option value=\"\">---------</option>\n<option value=\"AL\">Alabama</option>\n<option value=\"AK\">Alaska</option>\n<option value=\"AS\">American Samoa</option>\n<option value=\"AZ\">Arizona</option>\n<option value=\"AR\">Arkansas</option>\n<option value=\"AA\">Armed Forces Americas</option>\n<option value=\"AE\">Armed Forces Europe</option>\n<option value=\"AP\">Armed Forces Pacific</option>\n<option value=\"CA\">California</option>\n<option value=\"CO\">Colorado</option>\n<option value=\"CT\">Connecticut</option>\n<option value=\"DE\">Delaware</option>\n<option value=\"DC\">District of Columbia</option>\n<option value=\"FM\">Federated States of Micronesia</option>\n<option value=\"FL\">Florida</option>\n<option value=\"GA\" selected=\"selected\">Georgia</option>\n<option value=\"GU\">Guam</option>\n<option value=\"HI\">Hawaii</option>\n<option value=\"ID\">Idaho</option>\n<option value=\"IL\">Illinois</option>\n<option value=\"IN\">Indiana</option>\n<option value=\"IA\">Iowa</option>\n<option value=\"KS\">Kansas</option>\n<option value=\"KY\">Kentucky</option>\n<option value=\"LA\">Louisiana</option>\n<option value=\"ME\">Maine</option>\n<option value=\"MH\">Marshall Islands</option>\n<option value=\"MD\">Maryland</option>\n<option value=\"MA\">Massachusetts</option>\n<option value=\"MI\">Michigan</option>\n<option value=\"MN\">Minnesota</option>\n<option value=\"MS\">Mississippi</option>\n<option value=\"MO\">Missouri</option>\n<option value=\"MT\">Montana</option>\n<option value=\"NE\">Nebraska</option>\n<option value=\"NV\">Nevada</option>\n<option value=\"NH\">New Hampshire</option>\n<option value=\"NJ\">New Jersey</option>\n<option value=\"NM\">New Mexico</option>\n<option value=\"NY\">New York</option>\n<option value=\"NC\">North Carolina</option>\n<option value=\"ND\">North Dakota</option>\n<option value=\"MP\">Northern Mariana Islands</option>\n<option value=\"OH\">Ohio</option>\n<option value=\"OK\">Oklahoma</option>\n<option value=\"OR\">Oregon</option>\n<option value=\"PW\">Palau</option>\n<option value=\"PA\">Pennsylvania</option>\n<option value=\"PR\">Puerto Rico</option>\n<option value=\"RI\">Rhode Island</option>\n<option value=\"SC\">South Carolina</option>\n<option value=\"SD\">South Dakota</option>\n<option value=\"TN\">Tennessee</option>\n<option value=\"TX\">Texas</option>\n<option value=\"UT\">Utah</option>\n<option value=\"VT\">Vermont</option>\n<option value=\"VI\">Virgin Islands</option>\n<option value=\"VA\">Virginia</option>\n<option value=\"WA\">Washington</option>\n<option value=\"WV\">West Virginia</option>\n<option value=\"WI\">Wisconsin</option>\n<option value=\"WY\">Wyoming</option>\n</select>\"\"\"\n        self.assertEqual(str(self.form['postal_code']), usps_select_html)\n\n    def test_USStateSelect(self):\n        f = USStateSelect()\n        out = u'''<select name=\"state\">\n<option value=\"AL\">Alabama</option>\n<option value=\"AK\">Alaska</option>\n<option value=\"AS\">American Samoa</option>\n<option value=\"AZ\">Arizona</option>\n<option value=\"AR\">Arkansas</option>\n<option value=\"AA\">Armed Forces Americas</option>\n<option value=\"AE\">Armed Forces Europe</option>\n<option value=\"AP\">Armed Forces Pacific</option>\n<option value=\"CA\">California</option>\n<option value=\"CO\">Colorado</option>\n<option value=\"CT\">Connecticut</option>\n<option value=\"DE\">Delaware</option>\n<option value=\"DC\">District of Columbia</option>\n<option value=\"FL\">Florida</option>\n<option value=\"GA\">Georgia</option>\n<option value=\"GU\">Guam</option>\n<option value=\"HI\">Hawaii</option>\n<option value=\"ID\">Idaho</option>\n<option value=\"IL\" selected=\"selected\">Illinois</option>\n<option value=\"IN\">Indiana</option>\n<option value=\"IA\">Iowa</option>\n<option value=\"KS\">Kansas</option>\n<option value=\"KY\">Kentucky</option>\n<option value=\"LA\">Louisiana</option>\n<option value=\"ME\">Maine</option>\n<option value=\"MD\">Maryland</option>\n<option value=\"MA\">Massachusetts</option>\n<option value=\"MI\">Michigan</option>\n<option value=\"MN\">Minnesota</option>\n<option value=\"MS\">Mississippi</option>\n<option value=\"MO\">Missouri</option>\n<option value=\"MT\">Montana</option>\n<option value=\"NE\">Nebraska</option>\n<option value=\"NV\">Nevada</option>\n<option value=\"NH\">New Hampshire</option>\n<option value=\"NJ\">New Jersey</option>\n<option value=\"NM\">New Mexico</option>\n<option value=\"NY\">New York</option>\n<option value=\"NC\">North Carolina</option>\n<option value=\"ND\">North Dakota</option>\n<option value=\"MP\">Northern Mariana Islands</option>\n<option value=\"OH\">Ohio</option>\n<option value=\"OK\">Oklahoma</option>\n<option value=\"OR\">Oregon</option>\n<option value=\"PA\">Pennsylvania</option>\n<option value=\"PR\">Puerto Rico</option>\n<option value=\"RI\">Rhode Island</option>\n<option value=\"SC\">South Carolina</option>\n<option value=\"SD\">South Dakota</option>\n<option value=\"TN\">Tennessee</option>\n<option value=\"TX\">Texas</option>\n<option value=\"UT\">Utah</option>\n<option value=\"VT\">Vermont</option>\n<option value=\"VI\">Virgin Islands</option>\n<option value=\"VA\">Virginia</option>\n<option value=\"WA\">Washington</option>\n<option value=\"WV\">West Virginia</option>\n<option value=\"WI\">Wisconsin</option>\n<option value=\"WY\">Wyoming</option>\n</select>'''\n        self.assertEqual(f.render('state', 'IL'), out)\n\n    def test_USZipCodeField(self):\n        error_format = [u'Enter a zip code in the format XXXXX or XXXXX-XXXX.']\n        valid = {\n            '60606': '60606',\n            60606: '60606',\n            '04000': '04000',\n            '60606-1234': '60606-1234',\n        }\n        invalid = {\n            '4000': error_format,\n            '6060-1234': error_format,\n            '60606-': error_format,\n        }\n        self.assertFieldOutput(USZipCodeField, valid, invalid)\n\n    def test_USPhoneNumberField(self):\n        error_format = [u'Phone numbers must be in XXX-XXX-XXXX format.']\n        valid = {\n            '312-555-1212': '312-555-1212',\n            '3125551212': '312-555-1212',\n            '312 555-1212': '312-555-1212',\n            '(312) 555-1212': '312-555-1212',\n            '312 555 1212': '312-555-1212',\n            '312.555.1212': '312-555-1212',\n            '312.555-1212': '312-555-1212',\n            ' (312) 555.1212 ': '312-555-1212',\n        }\n        invalid = {\n            '555-1212': error_format,\n            '312-55-1212': error_format,\n        }\n        self.assertFieldOutput(USPhoneNumberField, valid, invalid)\n\n    def test_USStateField(self):\n        error_invalid = [u'Enter a U.S. state or territory.']\n        valid = {\n            'il': 'IL',\n            'IL': 'IL',\n            'illinois': 'IL',\n            '  illinois ': 'IL',\n        }\n        invalid = {\n            60606: error_invalid,\n        }\n        self.assertFieldOutput(USStateField, valid, invalid)\n\n    def test_USSocialSecurityNumberField(self):\n        error_invalid = [u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.']\n\n        valid = {\n            '987-65-4330': '987-65-4330',\n            '987654330': '987-65-4330',\n        }\n        invalid = {\n            '078-05-1120': error_invalid,\n        }\n        self.assertFieldOutput(USSocialSecurityNumberField, valid, invalid)\n
     
    277277        error_invalid = [u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.']
    278278
    279279        valid = {
    280             '987-65-4330': '987-65-4330',
    281             '987654330': '987-65-4330',
     280            '987-65-4330': '987-65-4330', # perfectly valid
     281
     282            # allow no hyphens input, forces output to hyphenated
     283            '987654330':   '987-65-4330',
    282284        }
    283285        invalid = {
    284             '078-05-1120': error_invalid,
     286            # improper format
     287            'A11-222-3333': error_invalid,   # can't have alphanumeric
     288            '12-12-3333'  : error_invalid,   # first block wrong length
     289            '123-1-3333'  : error_invalid,   # second block wrong length
     290            '123-12-333'  : error_invalid,   # third block wrong length
     291            '12312333'    : error_invalid,   # no hyphens too short
     292            '1231233333'  : error_invalid,   # no hyphens too long
     293
     294            # known bad blocks of proper format
     295            '078-05-1120' : error_invalid, # Known invalid
     296            '219-09-9999' : error_invalid, # Known invalid
     297            '000-12-1234' : error_invalid, # zeros in first block
     298            '123-00-1234' : error_invalid, # zeros in second block
     299            '123-12-0000' : error_invalid, # zeros in third block
     300            '666-12-1234' : error_invalid, # area block can't be 666
     301
     302            # known bad blocks input with no hyphens
     303            '078051120': error_invalid, # known invalid
     304            '219099999': error_invalid, # known invalid
     305            '000121234': error_invalid, # zeros in first block
     306            '123001234': error_invalid, # zeros in second block
     307            '123120000': error_invalid, # zeros in third block
     308            '666121234': error_invalid, # area block can't be 666
    285309        }
     310        self.assertFieldOutput(USSocialSecurityNumberField, valid, invalid)
     311
     312    def test_forces_number_to_no_hyphens_when_option_set(self):
     313        field = USSocialSecurityNumberField(no_hyphens=True)
     314        ssn = "123-45-6789"
     315        self.assertEqual("123456789", field.clean(ssn))
     316
     317    def test_is_not_valid_when_in_promotional_range(self):
     318        error_invalid = [u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.']
     319
     320        # 987-65-(4320 - 4329) is invalid
     321        valid = {
     322            '987-65-4319': '987-65-4319', # last good before range
     323            '987-65-4330': '987-65-4330', # first good after range
     324        }
     325        invalid = dict([("987-65-%d" % x, error_invalid) for x in range(4320, 4330)])
    286326        self.assertFieldOutput(USSocialSecurityNumberField, valid, invalid)
  • django/contrib/localflavor/us/forms.py

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
    <+>\"\"\"\nUSA-specific Form helpers\n\"\"\"\n\nfrom __future__ import absolute_import\n\nimport re\n\nfrom django.core.validators import EMPTY_VALUES\nfrom django.forms import ValidationError\nfrom django.forms.fields import Field, RegexField, Select, CharField\nfrom django.utils.encoding import smart_unicode\nfrom django.utils.translation import ugettext_lazy as _\n\n\nphone_digits_re = re.compile(r'^(?:1-?)?(\\d{3})[-\\.]?(\\d{3})[-\\.]?(\\d{4})$')\nssn_re = re.compile(r\"^(?P<area>\\d{3})[-\\ ]?(?P<group>\\d{2})[-\\ ]?(?P<serial>\\d{4})$\")\n\nclass USZipCodeField(RegexField):\n    default_error_messages = {\n        'invalid': _('Enter a zip code in the format XXXXX or XXXXX-XXXX.'),\n    }\n\n    def __init__(self, max_length=None, min_length=None, *args, **kwargs):\n        super(USZipCodeField, self).__init__(r'^\\d{5}(?:-\\d{4})?$',\n            max_length, min_length, *args, **kwargs)\n\nclass USPhoneNumberField(CharField):\n    default_error_messages = {\n        'invalid': _('Phone numbers must be in XXX-XXX-XXXX format.'),\n    }\n\n    def clean(self, value):\n        super(USPhoneNumberField, self).clean(value)\n        if value in EMPTY_VALUES:\n            return u''\n        value = re.sub('(\\(|\\)|\\s+)', '', smart_unicode(value))\n        m = phone_digits_re.search(value)\n        if m:\n            return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3))\n        raise ValidationError(self.error_messages['invalid'])\n\nclass USSocialSecurityNumberField(Field):\n    \"\"\"\n    A United States Social Security number.\n\n    Checks the following rules to determine whether the number is valid:\n\n        * Conforms to the XXX-XX-XXXX format.\n        * No group consists entirely of zeroes.\n        * The leading group is not \"666\" (block \"666\" will never be allocated).\n        * The number is not in the promotional block 987-65-4320 through\n          987-65-4329, which are permanently invalid.\n        * The number is not one known to be invalid due to otherwise widespread\n          promotional use or distribution (e.g., the Woolworth's number or the\n          1962 promotional number).\n    \"\"\"\n    default_error_messages = {\n        'invalid': _('Enter a valid U.S. Social Security number in XXX-XX-XXXX format.'),\n    }\n\n    def clean(self, value):\n        super(USSocialSecurityNumberField, self).clean(value)\n        if value in EMPTY_VALUES:\n            return u''\n        match = re.match(ssn_re, value)\n        if not match:\n            raise ValidationError(self.error_messages['invalid'])\n        area, group, serial = match.groupdict()['area'], match.groupdict()['group'], match.groupdict()['serial']\n\n        # First pass: no blocks of all zeroes.\n        if area == '000' or \\\n           group == '00' or \\\n           serial == '0000':\n            raise ValidationError(self.error_messages['invalid'])\n\n        # Second pass: promotional and otherwise permanently invalid numbers.\n        if area == '666' or \\\n           (area == '987' and group == '65' and 4320 <= int(serial) <= 4329) or \\\n           value == '078-05-1120' or \\\n           value == '219-09-9999':\n            raise ValidationError(self.error_messages['invalid'])\n        return u'%s-%s-%s' % (area, group, serial)\n\nclass USStateField(Field):\n    \"\"\"\n    A form field that validates its input is a U.S. state name or abbreviation.\n    It normalizes the input to the standard two-leter postal service\n    abbreviation for the given state.\n    \"\"\"\n    default_error_messages = {\n        'invalid': _('Enter a U.S. state or territory.'),\n    }\n\n    def clean(self, value):\n        from django.contrib.localflavor.us.us_states import STATES_NORMALIZED\n        super(USStateField, self).clean(value)\n        if value in EMPTY_VALUES:\n            return u''\n        try:\n            value = value.strip().lower()\n        except AttributeError:\n            pass\n        else:\n            try:\n                return STATES_NORMALIZED[value.strip().lower()].decode('ascii')\n            except KeyError:\n                pass\n        raise ValidationError(self.error_messages['invalid'])\n\nclass USStateSelect(Select):\n    \"\"\"\n    A Select widget that uses a list of U.S. states/territories as its choices.\n    \"\"\"\n    def __init__(self, attrs=None):\n        from django.contrib.localflavor.us.us_states import STATE_CHOICES\n        super(USStateSelect, self).__init__(attrs, choices=STATE_CHOICES)\n\nclass USPSSelect(Select):\n    \"\"\"\n    A Select widget that uses a list of US Postal Service codes as its\n    choices.\n    \"\"\"\n    def __init__(self, attrs=None):\n        from django.contrib.localflavor.us.us_states import USPS_CHOICES\n        super(USPSSelect, self).__init__(attrs, choices=USPS_CHOICES)\n
     
    5555          promotional use or distribution (e.g., the Woolworth's number or the
    5656          1962 promotional number).
    5757    """
     58
    5859    default_error_messages = {
    5960        'invalid': _('Enter a valid U.S. Social Security number in XXX-XX-XXXX format.'),
    6061    }
    6162
     63    def __init__(self, *args, **kwargs):
     64        self.no_hyphens = kwargs.pop("no_hyphens", False)
     65        super(USSocialSecurityNumberField, self).__init__(*args, **kwargs)
     66
    6267    def clean(self, value):
    63         super(USSocialSecurityNumberField, self).clean(value)
     68        value = super(USSocialSecurityNumberField, self).clean(value)
    6469        if value in EMPTY_VALUES:
    65             return u''
    66         match = re.match(ssn_re, value)
    67         if not match:
    68             raise ValidationError(self.error_messages['invalid'])
    69         area, group, serial = match.groupdict()['area'], match.groupdict()['group'], match.groupdict()['serial']
     70            return ''
    7071
    71         # First pass: no blocks of all zeroes.
    72         if area == '000' or \
    73            group == '00' or \
    74            serial == '0000':
     72        ssn_parts = self._get_ssn_parts(value)
     73        if not ssn_parts or self._is_invalid_ssn(ssn_parts):
    7574            raise ValidationError(self.error_messages['invalid'])
     75        return self._get_formatted_ssn(ssn_parts)
    7676
    77         # Second pass: promotional and otherwise permanently invalid numbers.
    78         if area == '666' or \
    79            (area == '987' and group == '65' and 4320 <= int(serial) <= 4329) or \
    80            value == '078-05-1120' or \
    81            value == '219-09-9999':
    82             raise ValidationError(self.error_messages['invalid'])
    83         return u'%s-%s-%s' % (area, group, serial)
     77    def _is_invalid_ssn(self, ssn_parts):
     78        return  self._has_zero_blocks(**ssn_parts) or \
     79                self._is_invalid_area(ssn_parts['area']) or \
     80                self._is_in_promotional_range(**ssn_parts) or \
     81                self._is_known_invalid(**ssn_parts)
     82
     83    def _get_formatted_ssn(self, ssn_parts):
     84        ssn = "%(area)s-%(group)s-%(serial)s" % ssn_parts
     85        if self.no_hyphens:
     86            ssn = ssn.replace('-', '')
     87        return ssn
     88
     89    def _get_ssn_parts(self, value):
     90        m = ssn_re.match(value)
     91        if m:
     92            return m.groupdict()
     93
     94    def _has_zero_blocks(self, area, group, serial):
     95        return area == '000' or group == '00' or serial == '0000'
     96
     97    def _is_invalid_area(self, area):
     98        return area == '666'
     99
     100    def _is_in_promotional_range(self, area, group, serial):
     101        return area == '987' and group == '65' and 4320 <= int(serial) <= 4329
     102
     103    def _is_known_invalid(self, area, group, serial):
     104        return area == '078' and group == '05' and serial == '1120' or \
     105               area == '219' and group == '09' and serial == '9999'
    84106
    85107class USStateField(Field):
    86108    """
  • docs/ref/contrib/localflavor.txt

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
    <+>==========================\nThe \"local flavor\" add-ons\n==========================\n\n.. module:: django.contrib.localflavor\n    :synopsis: A collection of various Django snippets that are useful only for\n               a particular country or culture.\n\nFollowing its \"batteries included\" philosophy, Django comes with assorted\npieces of code that are useful for particular countries or cultures. These are\ncalled the \"local flavor\" add-ons and live in the\n:mod:`django.contrib.localflavor` package.\n\nInside that package, country- or culture-specific code is organized into\nsubpackages, named using `ISO 3166 country codes`_.\n\nMost of the ``localflavor`` add-ons are localized form components deriving\nfrom the :doc:`forms </topics/forms/index>` framework -- for example, a\n:class:`~django.contrib.localflavor.us.forms.USStateField` that knows how to\nvalidate U.S. state abbreviations, and a\n:class:`~django.contrib.localflavor.fi.forms.FISocialSecurityNumber` that\nknows how to validate Finnish social security numbers.\n\nTo use one of these localized components, just import the relevant subpackage.\nFor example, here's how you can create a form with a field representing a\nFrench telephone number::\n\n    from django import forms\n    from django.contrib.localflavor.fr.forms import FRPhoneNumberField\n\n    class MyForm(forms.Form):\n        my_french_phone_no = FRPhoneNumberField()\n\nSupported countries\n===================\n\nCountries currently supported by :mod:`~django.contrib.localflavor` are:\n\n* Argentina_\n* Australia_\n* Austria_\n* Belgium_\n* Brazil_\n* Canada_\n* Chile_\n* China_\n* Colombia_\n* Croatia_\n* Czech_\n* Ecuador_\n* Finland_\n* France_\n* Germany_\n* Iceland_\n* India_\n* Indonesia_\n* Ireland_\n* Israel_\n* Italy_\n* Japan_\n* Kuwait_\n* Macedonia_\n* Mexico_\n* `The Netherlands`_\n* Norway_\n* Peru_\n* Poland_\n* Portugal_\n* Paraguay_\n* Romania_\n* Russia_\n* Slovakia_\n* Slovenia_\n* `South Africa`_\n* Spain_\n* Sweden_\n* Switzerland_\n* Turkey_\n* `United Kingdom`_\n* `United States of America`_\n* Uruguay_\n\nThe ``django.contrib.localflavor`` package also includes a ``generic`` subpackage,\ncontaining useful code that is not specific to one particular country or culture.\nCurrently, it defines date, datetime and split datetime input fields based on\nthose from :doc:`forms </topics/forms/index>`, but with non-US default formats.\nHere's an example of how to use them::\n\n    from django import forms\n    from django.contrib.localflavor import generic\n\n    class MyForm(forms.Form):\n        my_date_field = generic.forms.DateField()\n\n.. _ISO 3166 country codes: http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm\n.. _Argentina: `Argentina (ar)`_\n.. _Australia: `Australia (au)`_\n.. _Austria: `Austria (at)`_\n.. _Belgium: `Belgium (be)`_\n.. _Brazil: `Brazil (br)`_\n.. _Canada: `Canada (ca)`_\n.. _Chile: `Chile (cl)`_\n.. _China: `China (cn)`_\n.. _Colombia: `Colombia (co)`_\n.. _Croatia: `Croatia (hr)`_\n.. _Czech: `Czech (cz)`_\n.. _Ecuador: `Ecuador (ec)`_\n.. _Finland: `Finland (fi)`_\n.. _France: `France (fr)`_\n.. _Germany: `Germany (de)`_\n.. _The Netherlands: `The Netherlands (nl)`_\n.. _Iceland: `Iceland (is\\_)`_\n.. _India: `India (in\\_)`_\n.. _Indonesia: `Indonesia (id)`_\n.. _Ireland: `Ireland (ie)`_\n.. _Israel: `Israel (il)`_\n.. _Italy: `Italy (it)`_\n.. _Japan: `Japan (jp)`_\n.. _Kuwait: `Kuwait (kw)`_\n.. _Macedonia: `Macedonia (mk)`_\n.. _Mexico: `Mexico (mx)`_\n.. _Norway: `Norway (no)`_\n.. _Paraguay: `Paraguay (py)`_\n.. _Peru: `Peru (pe)`_\n.. _Poland: `Poland (pl)`_\n.. _Portugal: `Portugal (pt)`_\n.. _Romania: `Romania (ro)`_\n.. _Russia: `Russia (ru)`_\n.. _Slovakia: `Slovakia (sk)`_\n.. _Slovenia: `Slovenia (si)`_\n.. _South Africa: `South Africa (za)`_\n.. _Spain: `Spain (es)`_\n.. _Sweden: `Sweden (se)`_\n.. _Switzerland: `Switzerland (ch)`_\n.. _Turkey: `Turkey (tr)`_\n.. _United Kingdom: `United Kingdom (gb)`_\n.. _United States of America: `United States of America (us)`_\n.. _Uruguay: `Uruguay (uy)`_\n\nInternationalization of localflavor\n===================================\n\nLocalflavor has its own catalog of translations, in the directory\n``django/contrib/localflavor/locale``, and it's not loaded automatically like\nDjango's general catalog in ``django/conf/locale``. If you want localflavor's\ntexts to be translated, like form fields error messages, you must include\n:mod:`django.contrib.localflavor` in the :setting:`INSTALLED_APPS` setting, so\nthe internationalization system can find the catalog, as explained in\n:ref:`how-django-discovers-translations`.\n\nAdding flavors\n==============\n\nWe'd love to add more of these to Django, so please `create a ticket`_ with\nany code you'd like to contribute. One thing we ask is that you please use\nUnicode objects (``u'mystring'``) for strings, rather than setting the encoding\nin the file. See any of the existing flavors for examples.\n\n.. _create a ticket: http://code.djangoproject.com/simpleticket\n\nLocalflavor and backwards compatibility\n=======================================\n\nAs documented in our :ref:`API stability\n<misc-api-stability-localflavor>` policy, Django will always attempt\nto make :mod:`django.contrib.localflavor` reflect the officially\ngazetted policies of the appropriate local government authority. For\nexample, if a government body makes a change to add, alter, or remove\na province (or state, or county), that change will be reflected in\nDjango's localflavor in the next stable Django release.\n\nWhen a backwards-incompatible change is made (for example, the removal\nor renaming of a province) the localflavor in question will raise a\nwarning when that localflavor is imported. This provides a runtime\nindication that something may require attention.\n\nHowever, once you have addressed the backwards compatibility (for\nexample, auditing your code to see if any data migration is required),\nthe warning serves no purpose. The warning can then be supressed.\nFor example, to suppress the warnings raised by the Indonesian\nlocalflavor you would use the following code::\n\n    import warnings\n    warnings.filterwarnings('ignore',\n                            category=RuntimeWarning,\n                            module='django.contrib.localflavor.id')\n    from django.contrib.localflavor.id import forms as id_forms\n\n\nArgentina (``ar``)\n=============================================\n\n.. class:: ar.forms.ARPostalCodeField\n\n    A form field that validates input as either a classic four-digit Argentinian\n    postal code or a CPA_.\n\n.. _CPA: http://www.correoargentino.com.ar/consulta_cpa/home.php\n\n.. class:: ar.forms.ARDNIField\n\n    A form field that validates input as a Documento Nacional de Identidad (DNI)\n    number.\n\n.. class:: ar.forms.ARCUITField\n\n    A form field that validates input as a Codigo Unico de Identificacion\n    Tributaria (CUIT) number.\n\n.. class:: ar.forms.ARProvinceSelect\n\n    A ``Select`` widget that uses a list of Argentina's provinces and autonomous\n    cities as its choices.\n\nAustralia (``au``)\n=============================================\n\n.. versionadded:: 1.4\n\n.. class:: au.forms.AUPostCodeField\n\n    A form field that validates input as an Australian postcode.\n\n.. class:: au.forms.AUPhoneNumberField\n\n    A form field that validates input as an Australian phone number. Valid numbers\n    have ten digits.\n\n.. class:: au.forms.AUStateSelect\n\n    A ``Select`` widget that uses a list of Australian states/territories as its\n    choices.\n\n.. class:: au.models.AUPhoneNumberField\n\n    A model field that checks that the value is a valid Australian phone\n    number (ten digits).\n\n.. class:: au.models.AUStateField\n\n    A model field that forms represent as a ``forms.AUStateField`` field and\n    stores the three-letter Australian state abbreviation in the database.\n\n.. class:: au.models.AUPostCodeField\n\n    A model field that forms represent as a ``forms.AUPostCodeField`` field\n    and stores the four-digit Australian postcode in the database.\n\nAustria (``at``)\n================\n\n.. class:: at.forms.ATZipCodeField\n\n    A form field that validates its input as an Austrian zip code, with the\n    format XXXX (first digit must be greater than 0).\n\n.. class:: at.forms.ATStateSelect\n\n    A ``Select`` widget that uses a list of Austrian states as its choices.\n\n.. class:: at.forms.ATSocialSecurityNumberField\n\n    A form field that validates its input as an Austrian social security number.\n\nBelgium (``be``)\n================\n\n.. versionadded:: 1.3\n\n.. class:: be.forms.BEPhoneNumberField\n\n    A form field that validates input as a Belgium phone number, with one of\n    the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx,\n    0xx/xx.xx.xx, 04xx/xx.xx.xx, 0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx,\n    0xxxxxxxx or 04xxxxxxxx.\n\n.. class:: be.forms.BEPostalCodeField\n\n    A form field that validates input as a Belgium postal code, in the range\n    and format 1XXX-9XXX.\n\n.. class:: be.forms.BEProvinceSelect\n\n    A ``Select`` widget that uses a list of Belgium provinces as its\n    choices.\n\n.. class:: be.forms.BERegionSelect\n\n    A ``Select`` widget that uses a list of Belgium regions as its\n    choices.\n\nBrazil (``br``)\n===============\n\n.. class:: br.forms.BRPhoneNumberField\n\n    A form field that validates input as a Brazilian phone number, with the format\n    XX-XXXX-XXXX.\n\n.. class:: br.forms.BRZipCodeField\n\n    A form field that validates input as a Brazilian zip code, with the format\n    XXXXX-XXX.\n\n.. class:: br.forms.BRStateSelect\n\n    A ``Select`` widget that uses a list of Brazilian states/territories as its\n    choices.\n\n.. class:: br.forms.BRCPFField\n\n    A form field that validates input as `Brazilian CPF`_.\n\n    Input can either be of the format XXX.XXX.XXX-VD or be a group of 11 digits.\n\n.. _Brazilian CPF: http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas\n\n.. class:: br.forms.BRCNPJField\n\n    A form field that validates input as `Brazilian CNPJ`_.\n\n    Input can either be of the format XX.XXX.XXX/XXXX-XX or be a group of 14\n    digits.\n\n.. _Brazilian CNPJ: http://en.wikipedia.org/wiki/National_identification_number#Brazil\n\nCanada (``ca``)\n===============\n\n.. class:: ca.forms.CAPhoneNumberField\n\n    A form field that validates input as a Canadian phone number, with the format\n    XXX-XXX-XXXX.\n\n.. class:: ca.forms.CAPostalCodeField\n\n    A form field that validates input as a Canadian postal code, with the format\n    XXX XXX.\n\n.. class:: ca.forms.CAProvinceField\n\n    A form field that validates input as a Canadian province name or abbreviation.\n\n.. class:: ca.forms.CASocialInsuranceNumberField\n\n    A form field that validates input as a Canadian Social Insurance Number (SIN).\n    A valid number must have the format XXX-XXX-XXX and pass a `Luhn mod-10\n    checksum`_.\n\n.. _Luhn mod-10 checksum: http://en.wikipedia.org/wiki/Luhn_algorithm\n\n.. class:: ca.forms.CAProvinceSelect\n\n    A ``Select`` widget that uses a list of Canadian provinces and territories as\n    its choices.\n\nChile (``cl``)\n==============\n\n.. class:: cl.forms.CLRutField\n\n    A form field that validates input as a Chilean national identification number\n    ('Rol Unico Tributario' or RUT). The valid format is XX.XXX.XXX-X.\n\n.. class:: cl.forms.CLRegionSelect\n\n    A ``Select`` widget that uses a list of Chilean regions (Regiones) as its\n    choices.\n\nChina (``cn``)\n==============\n\n.. versionadded:: 1.4\n\n.. class:: cn.forms.CNProvinceSelect\n\n    A ``Select`` widget that uses a list of Chinese regions as its choices.\n\n.. class:: cn.forms.CNPostCodeField\n\n    A form field that validates input as a Chinese post code.\n    Valid formats are XXXXXX where X is digit.\n\n.. class:: cn.forms.CNIDCardField\n\n    A form field that validates input as a Chinese Identification Card Number.\n    Both 1st and 2nd generation ID Card Number are validated.\n\n.. class:: cn.forms.CNPhoneNumberField\n\n    A form field that validates input as a Chinese phone number.\n    Valid formats are 0XX-XXXXXXXX, composed of 3 or 4 digits of region code\n    and 7 or 8 digits of phone number.\n\n.. class:: cn.forms.CNCellNumberField\n\n    A form field that validates input as a Chinese mobile phone number.\n    Valid formats are like 1XXXXXXXXXX, where X is digit.\n    The second digit could only be 3, 5 and 8.\n\nColombia (``co``)\n=================\n\n.. versionadded:: 1.4\n\n.. class:: co.forms.CoDepartmentSelect\n\n    A ``Select`` widget that uses a list of Colombian departments\n    as its choices.\n\nCroatia (``hr``)\n================\n\n.. versionadded:: 1.4\n\n.. class:: hr.forms.HRCountySelect\n\n    A ``Select`` widget that uses a list of counties of Croatia as its choices.\n\n.. class:: hr.forms.HRPhoneNumberPrefixSelect\n\n    A ``Select`` widget that uses a list of phone number prefixes of Croatia as\n    its choices.\n\n.. class:: hr.forms.HRLicensePlatePrefixSelect\n\n    A ``Select`` widget that uses a list of vehicle license plate prefixes of\n    Croatia as its choices.\n\n.. class:: hr.forms.HRPhoneNumberField\n\n    A form field that validates input as a phone number of Croatia.\n    A valid format is a country code or a leading zero, area code prefix, 6 or 7\n    digit number; e.g. +385XXXXXXXX or 0XXXXXXXX\n    Validates fixed, mobile and FGSM numbers. Normalizes to a full number with\n    country code (+385 prefix).\n\n.. class:: hr.forms.HRLicensePlateField\n\n    A form field that validates input as a vehicle license plate of Croatia.\n    Normalizes to the specific format XX YYYY-XX where X is a letter and Y a\n    digit. There can be three or four digits.\n    Suffix is constructed from the shared letters of the Croatian and English\n    alphabets.\n    It is used for standardized license plates only. Special cases like license\n    plates for oldtimers, temporary license plates, government institution\n    license plates and customized license plates are not covered by this field.\n\n.. class:: hr.forms.HRPostalCodeField\n\n    A form field that validates input as a postal code of Croatia.\n    It consists of exactly five digits ranging from 10000 to 59999 inclusive.\n\n.. class:: hr.forms.HROIBField\n\n    A form field that validates input as a Personal Identification Number (OIB)\n    of Croatia.\n    It consists of exactly eleven digits.\n\n.. class:: hr.forms.HRJMBGField\n\n    A form field that validates input as a Unique Master Citizen Number (JMBG).\n    The number is still in use in Croatia, but it is being replaced by OIB.\n    This field works for other ex-Yugoslavia countries as well where the JMBG is\n    still in use.\n    The area segment of the JMBG is not validated because the citizens might\n    have emigrated to another ex-Yugoslavia country.\n    The number consists of exactly thirteen digits.\n\n.. class:: hr.forms.HRJMBAGField\n\n    A form field that validates input as a Unique Master Academic Citizen Number\n    (JMBAG) of Croatia.\n    This number is used by college students and professors in Croatia.\n    The number consists of exactly nineteen digits.\n\nCzech (``cz``)\n==============\n\n.. class:: cz.forms.CZPostalCodeField\n\n    A form field that validates input as a Czech postal code. Valid formats\n    are XXXXX or XXX XX, where X is a digit.\n\n.. class:: cz.forms.CZBirthNumberField\n\n    A form field that validates input as a Czech Birth Number.\n    A valid number must be in format XXXXXX/XXXX (slash is optional).\n\n.. class:: cz.forms.CZICNumberField\n\n    A form field that validates input as a Czech IC number field.\n\n.. class:: cz.forms.CZRegionSelect\n\n    A ``Select`` widget that uses a list of Czech regions as its choices.\n\nEcuador (``ec``)\n================\n\n.. versionadded:: 1.4\n\n.. class:: ec.forms.EcProvinceSelect\n\n    A ``Select`` widget that uses a list of Ecuatorian provinces as\n    its choices.\n\nFinland (``fi``)\n================\n\n.. class:: fi.forms.FISocialSecurityNumber\n\n    A form field that validates input as a Finnish social security number.\n\n.. class:: fi.forms.FIZipCodeField\n\n    A form field that validates input as a Finnish zip code. Valid codes\n    consist of five digits.\n\n.. class:: fi.forms.FIMunicipalitySelect\n\n    A ``Select`` widget that uses a list of Finnish municipalities as its\n    choices.\n\nFrance (``fr``)\n===============\n\n.. class:: fr.forms.FRPhoneNumberField\n\n    A form field that validates input as a French local phone number. The\n    correct format is 0X XX XX XX XX. 0X.XX.XX.XX.XX and 0XXXXXXXXX validate\n    but are corrected to 0X XX XX XX XX.\n\n.. class:: fr.forms.FRZipCodeField\n\n    A form field that validates input as a French zip code. Valid codes\n    consist of five digits.\n\n.. class:: fr.forms.FRDepartmentSelect\n\n    A ``Select`` widget that uses a list of French departments as its choices.\n\nGermany (``de``)\n================\n\n.. class:: de.forms.DEIdentityCardNumberField\n\n    A form field that validates input as a German identity card number\n    (Personalausweis_). Valid numbers have the format\n    XXXXXXXXXXX-XXXXXXX-XXXXXXX-X, with no group consisting entirely of zeroes.\n\n.. _Personalausweis: http://de.wikipedia.org/wiki/Personalausweis\n\n.. class:: de.forms.DEZipCodeField\n\n    A form field that validates input as a German zip code. Valid codes\n    consist of five digits.\n\n.. class:: de.forms.DEStateSelect\n\n    A ``Select`` widget that uses a list of German states as its choices.\n\nThe Netherlands (``nl``)\n========================\n\n.. class:: nl.forms.NLPhoneNumberField\n\n    A form field that validates input as a Dutch telephone number.\n\n.. class:: nl.forms.NLSofiNumberField\n\n    A form field that validates input as a Dutch social security number\n    (SoFI/BSN).\n\n.. class:: nl.forms.NLZipCodeField\n\n    A form field that validates input as a Dutch zip code.\n\n.. class:: nl.forms.NLProvinceSelect\n\n    A ``Select`` widget that uses a list of Dutch provinces as its list of\n    choices.\n\nIceland (``is_``)\n=================\n\n.. class:: is_.forms.ISIdNumberField\n\n    A form field that validates input as an Icelandic identification number\n    (kennitala). The format is XXXXXX-XXXX.\n\n.. class:: is_.forms.ISPhoneNumberField\n\n    A form field that validates input as an Icelandtic phone number (seven\n    digits with an optional hyphen or space after the first three digits).\n\n.. class:: is_.forms.ISPostalCodeSelect\n\n    A ``Select`` widget that uses a list of Icelandic postal codes as its\n    choices.\n\nIndia (``in_``)\n===============\n\n.. class:: in_.forms.INStateField\n\n    A form field that validates input as an Indian state/territory name or\n    abbreviation. Input is normalized to the standard two-letter vehicle\n    registration abbreviation for the given state or territory.\n\n.. class:: in_.forms.INZipCodeField\n\n    A form field that validates input as an Indian zip code, with the\n    format XXXXXXX.\n\n.. class:: in_.forms.INStateSelect\n\n    A ``Select`` widget that uses a list of Indian states/territories as its\n    choices.\n\n.. versionadded:: 1.4\n\n.. class:: in_.forms.INPhoneNumberField\n\n    A form field that validates that the data is a valid Indian phone number,\n    including the STD code. It's normalised to 0XXX-XXXXXXX or 0XXX XXXXXXX\n    format. The first string is the STD code which is a '0' followed by 2-4\n    digits. The second string is 8 digits if the STD code is 3 digits, 7\n    digits if the STD code is 4 digits and 6 digits if the STD code is 5\n    digits. The second string will start with numbers between 1 and 6. The\n    separator is either a space or a hyphen.\n\nIreland (``ie``)\n================\n\n.. class:: ie.forms.IECountySelect\n\n    A ``Select`` widget that uses a list of Irish Counties as its choices.\n\nIndonesia (``id``)\n==================\n\n.. class:: id.forms.IDPostCodeField\n\n    A form field that validates input as an Indonesian post code field.\n\n.. class:: id.forms.IDProvinceSelect\n\n    A ``Select`` widget that uses a list of Indonesian provinces as its choices.\n\n.. versionchanged:: 1.3\n    The province \"Nanggroe Aceh Darussalam (NAD)\" has been removed\n    from the province list in favor of the new official designation\n    \"Aceh (ACE)\".\n\n.. class:: id.forms.IDPhoneNumberField\n\n    A form field that validates input as an Indonesian telephone number.\n\n.. class:: id.forms.IDLicensePlatePrefixSelect\n\n    A ``Select`` widget that uses a list of Indonesian license plate\n    prefix code as its choices.\n\n.. class:: id.forms.IDLicensePlateField\n\n    A form field that validates input as an Indonesian vehicle license plate.\n\n.. class:: id.forms.IDNationalIdentityNumberField\n\n    A form field that validates input as an Indonesian national identity\n    number (`NIK`_/KTP). The output will be in the format of\n    'XX.XXXX.DDMMYY.XXXX'. Dots or spaces can be used in the input to break\n    down the numbers.\n\n.. _NIK: http://en.wikipedia.org/wiki/Indonesian_identity_card\n\nIsrael (``il``)\n===============\n\n.. class:: il.forms.ILPostalCodeField\n\n    A form field that validates its input as an Israeli five-digit postal code.\n\n.. class:: il.forms.ILIDNumberField\n\n    A form field that validates its input as an `Israeli identification number`_.\n    The output will be in the format of a 2-9 digit number, consisting of a\n    1-8 digit ID number followed by a single checksum digit, calculated using\n    the `Luhn algorithm`_.\n\n    Input may contain an optional hyphen separating the ID number from the checksum\n    digit.\n\n.. _Israeli identification number: http://he.wikipedia.org/wiki/%D7%9E%D7%A1%D7%A4%D7%A8_%D7%96%D7%94%D7%95%D7%AA_(%D7%99%D7%A9%D7%A8%D7%90%D7%9C)\n.. _Luhn algorithm: http://en.wikipedia.org/wiki/Luhn_algorithm\n\nItaly (``it``)\n==============\n\n.. class:: it.forms.ITSocialSecurityNumberField\n\n    A form field that validates input as an Italian social security number\n    (`codice fiscale`_).\n\n.. _codice fiscale: http://www.agenziaentrate.it/ilwwcm/connect/Nsi/Servizi/Codice+fiscale+-+tessera+sanitaria/NSI+Informazioni+sulla+codificazione+delle+persone+fisiche\n\n.. class:: it.forms.ITVatNumberField\n\n    A form field that validates Italian VAT numbers (partita IVA).\n\n.. class:: it.forms.ITZipCodeField\n\n    A form field that validates input as an Italian zip code. Valid codes\n    must have five digits.\n\n.. class:: it.forms.ITProvinceSelect\n\n    A ``Select`` widget that uses a list of Italian provinces as its choices.\n\n.. class:: it.forms.ITRegionSelect\n\n    A ``Select`` widget that uses a list of Italian regions as its choices.\n\nJapan (``jp``)\n==============\n\n.. class:: jp.forms.JPPostalCodeField\n\n    A form field that validates input as a Japanese postcode. It accepts seven\n    digits, with or without a hyphen.\n\n.. class:: jp.forms.JPPrefectureSelect\n\n    A ``Select`` widget that uses a list of Japanese prefectures as its choices.\n\nKuwait (``kw``)\n===============\n\n.. class:: kw.forms.KWCivilIDNumberField\n\n    A form field that validates input as a Kuwaiti Civil ID number. A valid\n    Civil ID number must obey the following rules:\n\n    * The number consist of 12 digits.\n    * The birthdate of the person is a valid date.\n    * The calculated checksum equals to the last digit of the Civil ID.\n\nMacedonia (``mk``)\n===================\n\n.. versionadded:: 1.4\n\n.. class:: mk.forms.MKIdentityCardNumberField\n\n    A form field that validates input as a Macedonian identity card number.\n    Both old and new identity card numbers are supported.\n\n\n.. class:: mk.forms.MKMunicipalitySelect\n\n    A form ``Select`` widget that uses a list of Macedonian municipalities as\n    choices.\n\n\n.. class:: mk.forms.UMCNField\n\n    A form field that validates input as a unique master citizen\n    number.\n\n    The format of the unique master citizen number is not unique\n    to Macedonia. For more information see:\n    https://secure.wikimedia.org/wikipedia/en/wiki/Unique_Master_Citizen_Number\n\n    A value will pass validation if it complies to the following rules:\n\n    * Consists of exactly 13 digits\n    * The first 7 digits represent a valid past date in the format DDMMYYY\n    * The last digit of the UMCN passes a checksum test\n\n\n.. class:: mk.models.MKIdentityCardNumberField\n\n   A model field that forms represent as a\n   ``forms.MKIdentityCardNumberField`` field.\n\n\n.. class:: mk.models.MKMunicipalityField\n\n   A model field that forms represent as a\n   ``forms.MKMunicipalitySelect`` and stores the 2 character code of the\n   municipality in the database.\n\n\n.. class:: mk.models.UMCNField\n\n   A model field that forms represent as a ``forms.UMCNField`` field.\n\n\nMexico (``mx``)\n===============\n\n.. class:: mx.forms.MXZipCodeField\n\n    .. versionadded:: 1.4\n\n    A form field that accepts a Mexican Zip Code.\n\n    More info about this: List of postal codes in Mexico (zipcodes_)\n\n.. _zipcodes: http://en.wikipedia.org/wiki/List_of_postal_codes_in_Mexico\n\n.. class:: mx.forms.MXRFCField\n\n    .. versionadded:: 1.4\n\n    A form field that validates a Mexican *Registro Federal de Contribuyentes* for\n    either **Persona física** or **Persona moral**. This field accepts RFC strings\n    whether or not it contains a *homoclave*.\n\n    More info about this: Registro Federal de Contribuyentes (rfc_)\n\n.. _rfc: http://es.wikipedia.org/wiki/Registro_Federal_de_Contribuyentes_(M%C3%A9xico)\n\n.. class:: mx.forms.MXCURPField\n\n   .. versionadded:: 1.4\n\n   A field that validates a Mexican *Clave Única de Registro de Población*.\n\n   More info about this: Clave Unica de Registro de Poblacion (curp_)\n\n.. _curp: http://www.condusef.gob.mx/index.php/clave-unica-de-registro-de-poblacion-curp\n\n.. class:: mx.forms.MXStateSelect\n\n    A ``Select`` widget that uses a list of Mexican states as its choices.\n\n.. class:: mx.models.MXStateField\n\n    .. versionadded:: 1.4\n\n    A model field that stores the three-letter Mexican state abbreviation in the\n    database.\n\n.. class:: mx.models.MXZipCodeField\n\n    .. versionadded:: 1.4\n\n    A model field that forms represent as a ``forms.MXZipCodeField`` field and\n    stores the five-digit Mexican zip code.\n\n.. class:: mx.models.MXRFCField\n\n    .. versionadded:: 1.4\n\n    A model field that forms represent as a ``forms.MXRFCField`` field and\n    stores the value of a valid Mexican RFC.\n\n.. class:: mx.models.MXCURPField\n\n    .. versionadded:: 1.4\n\n    A model field that forms represent as a ``forms.MXCURPField`` field and\n    stores the value of a valid Mexican CURP.\n\nAdditionally, a choice tuple is provided in ``django.contrib.localflavor.mx.mx_states``,\nallowing customized model and form fields, and form presentations, for subsets of\nMexican states abbreviations:\n\n.. data:: mx.mx_states.STATE_CHOICES\n\n    A tuple of choices of the states abbreviations for all 31 Mexican states,\n    plus the `Distrito Federal`.\n\nNorway (``no``)\n===============\n\n.. class:: no.forms.NOSocialSecurityNumber\n\n    A form field that validates input as a Norwegian social security number\n    (personnummer_).\n\n.. _personnummer: http://no.wikipedia.org/wiki/Personnummer\n\n.. class:: no.forms.NOZipCodeField\n\n    A form field that validates input as a Norwegian zip code. Valid codes\n    have four digits.\n\n.. class:: no.forms.NOMunicipalitySelect\n\n    A ``Select`` widget that uses a list of Norwegian municipalities (fylker) as\n    its choices.\n\nParaguay (``py``)\n=================\n\n.. versionadded:: 1.4\n\n.. class:: py.forms.PyDepartmentSelect\n\n    A ``Select`` widget with a list of Paraguayan departments as choices.\n\n.. class:: py.forms.PyNumberedDepartmentSelect\n\n    A ``Select`` widget with a roman numbered list of Paraguayan departments as choices.\n\nPeru (``pe``)\n=============\n\n.. class:: pe.forms.PEDNIField\n\n    A form field that validates input as a DNI (Peruvian national identity)\n    number.\n\n.. class:: pe.forms.PERUCField\n\n    A form field that validates input as an RUC (Registro Unico de\n    Contribuyentes) number. Valid RUC numbers have 11 digits.\n\n.. class:: pe.forms.PEDepartmentSelect\n\n    A ``Select`` widget that uses a list of Peruvian Departments as its choices.\n\nPoland (``pl``)\n===============\n\n.. class:: pl.forms.PLPESELField\n\n    A form field that validates input as a Polish national identification number\n    (PESEL_).\n\n.. _PESEL: http://en.wikipedia.org/wiki/PESEL\n\n.. versionadded:: 1.4\n\n.. class:: pl.forms.PLNationalIDCardNumberField\n\n    A form field that validates input as a Polish National ID Card number. The\n    valid format is AAAXXXXXX, where A is letter (A-Z), X is digit and left-most\n    digit is checksum digit. More information about checksum calculation algorithm\n    see `Polish identity card`_.\n\n.. _`Polish identity card`: http://en.wikipedia.org/wiki/Polish_identity_card\n\n.. class:: pl.forms.PLREGONField\n\n    A form field that validates input as a Polish National Official Business\n    Register Number (REGON_), having either seven or nine digits. The checksum\n    algorithm used for REGONs is documented at\n    http://wipos.p.lodz.pl/zylla/ut/nip-rego.html.\n\n.. _REGON: http://www.stat.gov.pl/bip/regon_ENG_HTML.htm\n\n.. class:: pl.forms.PLPostalCodeField\n\n    A form field that validates input as a Polish postal code. The valid format\n    is XX-XXX, where X is a digit.\n\n.. class:: pl.forms.PLNIPField\n\n    A form field that validates input as a Polish Tax Number (NIP). Valid formats\n    are XXX-XXX-XX-XX, XXX-XX-XX-XXX or XXXXXXXXXX. The checksum algorithm used\n    for NIPs is documented at http://wipos.p.lodz.pl/zylla/ut/nip-rego.html.\n\n.. class:: pl.forms.PLCountySelect\n\n    A ``Select`` widget that uses a list of Polish administrative units as its\n    choices.\n\n.. class:: pl.forms.PLProvinceSelect\n\n    A ``Select`` widget that uses a list of Polish voivodeships (administrative\n    provinces) as its choices.\n\nPortugal (``pt``)\n=================\n\n.. class:: pt.forms.PTZipCodeField\n\n    A form field that validates input as a Portuguese zip code.\n\n.. class:: pt.forms.PTPhoneNumberField\n\n    A form field that validates input as a Portuguese phone number.\n    Valid numbers have 9 digits (may include spaces) or start by 00\n    or + (international).\n\nRomania (``ro``)\n================\n\n.. class:: ro.forms.ROCIFField\n\n    A form field that validates Romanian fiscal identification codes (CIF). The\n    return value strips the leading RO, if given.\n\n.. class:: ro.forms.ROCNPField\n\n    A form field that validates Romanian personal numeric codes (CNP).\n\n.. class:: ro.forms.ROCountyField\n\n    A form field that validates its input as a Romanian county (judet) name or\n    abbreviation. It normalizes the input to the standard vehicle registration\n    abbreviation for the given county. This field will only accept names written\n    with diacritics; consider using ROCountySelect as an alternative.\n\n.. class:: ro.forms.ROCountySelect\n\n    A ``Select`` widget that uses a list of Romanian counties (judete) as its\n    choices.\n\n.. class:: ro.forms.ROIBANField\n\n    A form field that validates its input as a Romanian International Bank\n    Account Number (IBAN). The valid format is ROXX-XXXX-XXXX-XXXX-XXXX-XXXX,\n    with or without hyphens.\n\n.. class:: ro.forms.ROPhoneNumberField\n\n    A form field that validates Romanian phone numbers, short special numbers\n    excluded.\n\n.. class:: ro.forms.ROPostalCodeField\n\n    A form field that validates Romanian postal codes.\n\nRussia (``ru``)\n===============\n\n.. versionadded:: 1.4\n\n.. class:: ru.forms.RUPostalCodeField\n\n    Russian Postal code field. The valid format is XXXXXX, where X is any\n    digit and the first digit is not zero.\n\n.. class:: ru.forms.RUCountySelect\n\n    A ``Select`` widget that uses a list of Russian Counties as its choices.\n\n.. class:: ru.forms.RURegionSelect\n\n    A ``Select`` widget that uses a list of Russian Regions as its choices.\n\n.. class:: ru.forms.RUPassportNumberField\n\n    Russian internal passport number. The valid format is XXXX XXXXXX, where X\n    is any digit.\n\n.. class:: ru.forms.RUAlienPassportNumberField\n\n    Russian alien's passport number. The valid format is XX XXXXXXX, where X\n    is any digit.\n\nSlovakia (``sk``)\n=================\n\n.. class:: sk.forms.SKPostalCodeField\n\n    A form field that validates input as a Slovak postal code. Valid formats\n    are XXXXX or XXX XX, where X is a digit.\n\n.. class:: sk.forms.SKDistrictSelect\n\n    A ``Select`` widget that uses a list of Slovak districts as its choices.\n\n.. class:: sk.forms.SKRegionSelect\n\n    A ``Select`` widget that uses a list of Slovak regions as its choices.\n\nSlovenia (``si``)\n=================\n\n.. class:: si.forms.SIEMSOField\n\n    A form field that validates input as Slovenian personal identification\n    number and stores gender and birthday to self.info dictionary.\n\n.. class:: si.forms.SITaxNumberField\n\n    A form field that validates input as a Slovenian tax number. Valid input\n    is SIXXXXXXXX or XXXXXXXX.\n\n.. class:: si.forms.SIPhoneNumberField\n\n    A form field that validates input as a Slovenian phone number. Phone\n    number must contain at least local area code with optional country code.\n\n.. class:: si.forms.SIPostalCodeField\n\n    A form field that provides a choice field of major Slovenian postal\n    codes.\n\n.. class:: si.forms.SIPostalCodeSelect\n\n    A ``Select`` widget that uses a list of major Slovenian postal codes as\n    its choices.\n\n\nSouth Africa (``za``)\n=====================\n\n.. class:: za.forms.ZAIDField\n\n    A form field that validates input as a South African ID number. Validation\n    uses the Luhn checksum and a simplistic (i.e., not entirely accurate) check\n    for birth date.\n\n.. class:: za.forms.ZAPostCodeField\n\n    A form field that validates input as a South African postcode. Valid\n    postcodes must have four digits.\n\nSpain (``es``)\n==============\n\n.. class:: es.forms.ESIdentityCardNumberField\n\n    A form field that validates input as a Spanish NIF/NIE/CIF (Fiscal\n    Identification Number) code.\n\n.. class:: es.forms.ESCCCField\n\n    A form field that validates input as a Spanish bank account number (Codigo\n    Cuenta Cliente or CCC). A valid CCC number has the format\n    EEEE-OOOO-CC-AAAAAAAAAA, where the E, O, C and A digits denote the entity,\n    office, checksum and account, respectively. The first checksum digit\n    validates the entity and office. The second checksum digit validates the\n    account. It is also valid to use a space as a delimiter, or to use no\n    delimiter.\n\n.. class:: es.forms.ESPhoneNumberField\n\n    A form field that validates input as a Spanish phone number. Valid numbers\n    have nine digits, the first of which is 6, 8 or 9.\n\n.. class:: es.forms.ESPostalCodeField\n\n    A form field that validates input as a Spanish postal code. Valid codes\n    have five digits, the first two being in the range 01 to 52, representing\n    the province.\n\n.. class:: es.forms.ESProvinceSelect\n\n    A ``Select`` widget that uses a list of Spanish provinces as its choices.\n\n.. class:: es.forms.ESRegionSelect\n\n    A ``Select`` widget that uses a list of Spanish regions as its choices.\n\nSweden (``se``)\n===============\n\n.. class:: se.forms.SECountySelect\n\n    A Select form widget that uses a list of the Swedish counties (län) as its\n    choices.\n\n    The cleaned value is the official county code -- see\n    http://en.wikipedia.org/wiki/Counties_of_Sweden for a list.\n\n.. class:: se.forms.SEOrganisationNumber\n\n    A form field that validates input as a Swedish organisation number\n    (organisationsnummer).\n\n    It accepts the same input as SEPersonalIdentityField (for sole\n    proprietorships (enskild firma). However, co-ordination numbers are not\n    accepted.\n\n    It also accepts ordinary Swedish organisation numbers with the format\n    NNNNNNNNNN.\n\n    The return value will be YYYYMMDDXXXX for sole proprietors, and NNNNNNNNNN\n    for other organisations.\n\n.. class:: se.forms.SEPersonalIdentityNumber\n\n    A form field that validates input as a Swedish personal identity number\n    (personnummer).\n\n    The correct formats are YYYYMMDD-XXXX, YYYYMMDDXXXX, YYMMDD-XXXX,\n    YYMMDDXXXX and YYMMDD+XXXX.\n\n    A \\+ indicates that the person is older than 100 years, which will be taken\n    into consideration when the date is validated.\n\n    The checksum will be calculated and checked. The birth date is checked\n    to be a valid date.\n\n    By default, co-ordination numbers (samordningsnummer) will be accepted. To\n    only allow real personal identity numbers, pass the keyword argument\n    coordination_number=False to the constructor.\n\n    The cleaned value will always have the format YYYYMMDDXXXX.\n\n.. class:: se.forms.SEPostalCodeField\n\n    A form field that validates input as a Swedish postal code (postnummer).\n    Valid codes consist of five digits (XXXXX). The number can optionally be\n    formatted with a space after the third digit (XXX XX).\n\n    The cleaned value will never contain the space.\n\nSwitzerland (``ch``)\n====================\n\n.. class:: ch.forms.CHIdentityCardNumberField\n\n    A form field that validates input as a Swiss identity card number.\n    A valid number must confirm to the X1234567<0 or 1234567890 format and\n    have the correct checksums.\n\n.. class:: ch.forms.CHPhoneNumberField\n\n    A form field that validates input as a Swiss phone number. The correct\n    format is 0XX XXX XX XX. 0XX.XXX.XX.XX and 0XXXXXXXXX validate but are\n    corrected to 0XX XXX XX XX.\n\n.. class:: ch.forms.CHZipCodeField\n\n    A form field that validates input as a Swiss zip code. Valid codes\n    consist of four digits.\n\n.. class:: ch.forms.CHStateSelect\n\n    A ``Select`` widget that uses a list of Swiss states as its choices.\n\nTurkey (``tr``)\n===============\n\n.. class:: tr.forms.TRZipCodeField\n\n    A form field that validates input as a Turkish zip code. Valid codes\n    consist of five digits.\n\n.. class:: tr.forms.TRPhoneNumberField\n\n    A form field that validates input as a Turkish phone number. The correct\n    format is 0xxx xxx xxxx. +90xxx xxx xxxx and inputs without spaces also\n    validates. The result is normalized to xxx xxx xxxx format.\n\n.. class:: tr.forms.TRIdentificationNumberField\n\n    A form field that validates input as a TR identification number. A valid\n    number must satisfy the following:\n\n    * The number consist of 11 digits.\n    * The first digit cannot be 0.\n    * (sum(1st, 3rd, 5th, 7th, 9th)*7 - sum(2nd,4th,6th,8th)) % 10) must be\n      equal to the 10th digit.\n    * (sum(1st to 10th) % 10) must be equal to the 11th digit.\n\n.. class:: tr.forms.TRProvinceSelect\n\n    A ``select`` widget that uses a list of Turkish provinces as its choices.\n\nUnited Kingdom (``gb``)\n=======================\n\n.. class:: gb.forms.GBPostcodeField\n\n    A form field that validates input as a UK postcode. The regular\n    expression used is sourced from the schema for British Standard BS7666\n    address types at http://www.cabinetoffice.gov.uk/media/291293/bs7666-v2-0.xml.\n\n.. class:: gb.forms.GBCountySelect\n\n    A ``Select`` widget that uses a list of UK counties/regions as its choices.\n\n.. class:: gb.forms.GBNationSelect\n\n    A ``Select`` widget that uses a list of UK nations as its choices.\n\nUnited States of America (``us``)\n=================================\n\n.. class:: us.forms.USPhoneNumberField\n\n    A form field that validates input as a U.S. phone number.\n\n.. class:: us.forms.USSocialSecurityNumberField\n\n    A form field that validates input as a U.S. Social Security Number (SSN).\n    A valid SSN must obey the following rules:\n\n    * Format of XXX-XX-XXXX\n    * No group of digits consisting entirely of zeroes\n    * Leading group of digits cannot be 666\n    * Number not in promotional block 987-65-4320 through 987-65-4329\n    * Number not one known to be invalid due to widespread promotional\n      use or distribution (e.g., the Woolworth's number or the 1962\n      promotional number)\n\n.. class:: us.forms.USStateField\n\n    A form field that validates input as a U.S. state name or abbreviation. It\n    normalizes the input to the standard two-letter postal service abbreviation\n    for the given state.\n\n.. class:: us.forms.USZipCodeField\n\n    A form field that validates input as a U.S. ZIP code. Valid formats are\n    XXXXX or XXXXX-XXXX.\n\n.. class:: us.forms.USStateSelect\n\n    A form ``Select`` widget that uses a list of U.S. states/territories as its\n    choices.\n\n.. class:: us.forms.USPSSelect\n\n    A form ``Select`` widget that uses a list of U.S Postal Service\n    state, territory and country abbreviations as its choices.\n\n.. class:: us.models.PhoneNumberField\n\n    A :class:`CharField` that checks that the value is a valid U.S.A.-style phone\n    number (in the format ``XXX-XXX-XXXX``).\n\n.. class:: us.models.USStateField\n\n    A model field that forms represent as a ``forms.USStateField`` field and\n    stores the two-letter U.S. state abbreviation in the database.\n\n.. class:: us.models.USPostalCodeField\n\n    A model field that forms represent as a ``forms.USPSSelect`` field\n    and stores the two-letter U.S Postal Service abbreviation in the\n    database.\n\nAdditionally, a variety of choice tuples are provided in\n``django.contrib.localflavor.us.us_states``, allowing customized model\nand form fields, and form presentations, for subsets of U.S states,\nterritories and U.S Postal Service abbreviations:\n\n.. data:: us.us_states.CONTIGUOUS_STATES\n\n    A tuple of choices of the postal abbreviations for the\n    contiguous or \"lower 48\" states (i.e., all except Alaska and\n    Hawaii), plus the District of Columbia.\n\n.. data:: us.us_states.US_STATES\n\n    A tuple of choices of the postal abbreviations for all\n    50 U.S. states, plus the District of Columbia.\n\n.. data:: us.us_states.US_TERRITORIES\n\n    A tuple of choices of the postal abbreviations for U.S\n    territories: American Samoa, Guam, the Northern Mariana Islands,\n    Puerto Rico and the U.S. Virgin Islands.\n\n.. data:: us.us_states.ARMED_FORCES_STATES\n\n    A tuple of choices of the postal abbreviations of the three U.S\n    military postal \"states\": Armed Forces Americas, Armed Forces\n    Europe and Armed Forces Pacific.\n\n.. data:: us.us_states.COFA_STATES\n\n    A tuple of choices of the postal abbreviations of the three\n    independent nations which, under the Compact of Free Association,\n    are served by the U.S. Postal Service: the Federated States of\n    Micronesia, the Marshall Islands and Palau.\n\n.. data:: us.us_states.OBSOLETE_STATES\n\n    A tuple of choices of obsolete U.S Postal Service state\n    abbreviations: the former abbreviation for the Northern Mariana\n    Islands, plus the Panama Canal Zone, the Philippines and the\n    former Pacific trust territories.\n\n.. data:: us.us_states.STATE_CHOICES\n\n    A tuple of choices of all postal abbreviations corresponding to U.S states or\n    territories, and the District of Columbia..\n\n.. data:: us.us_states.USPS_CHOICES\n\n    A tuple of choices of all postal abbreviations recognized by the\n    U.S Postal Service (including all states and territories, the\n    District of Columbia, armed forces \"states\" and independent\n    nations serviced by USPS).\n\nUruguay (``uy``)\n================\n\n.. class:: uy.forms.UYCIField\n\n    A field that validates Uruguayan 'Cedula de identidad' (CI) numbers.\n\n.. class:: uy.forms.UYDepartamentSelect\n\n    A ``Select`` widget that uses a list of  Uruguayan departments as its\n    choices.\n
     
    12941294      use or distribution (e.g., the Woolworth's number or the 1962
    12951295      promotional number)
    12961296
     1297    As an optional argument, you can instantiate ``forms.USSocialSecurityNumberField``
     1298    with 'no_hyphens=True' to remove hyphens from SSN output. (XXXXXXXXX)
     1299
    12971300.. class:: us.forms.USStateField
    12981301
    12991302    A form field that validates input as a U.S. state name or abbreviation. It
Back to Top