United States of America (us)

Forms

USA-specific Form helpers

class localflavor.us.forms.USPSSelect(attrs=None)[source]

A Select widget that uses a list of US Postal Service codes as its choices.

class localflavor.us.forms.USPhoneNumberField(max_length=None, min_length=None, *args, **kwargs)[source]

A form field that validates input as a U.S. phone number.

class localflavor.us.forms.USSocialSecurityNumberField(required=True, widget=None, label=None, initial=None, help_text=None, error_messages=None, show_hidden_initial=False, validators=[], localize=False)[source]

A United States Social Security number.

Checks the following rules to determine whether the number is valid:

  • Conforms to the XXX-XX-XXXX format.
  • No group consists entirely of zeroes.
  • The leading group is not “666” (block “666” will never be allocated).
  • The number is not in the promotional block 987-65-4320 through 987-65-4329, which are permanently invalid.
  • The number is not one known to be invalid due to otherwise widespread promotional use or distribution (e.g., the Woolworth’s number or the 1962 promotional number).
class localflavor.us.forms.USStateField(required=True, widget=None, label=None, initial=None, help_text=None, error_messages=None, show_hidden_initial=False, validators=[], localize=False)[source]

A form field that validates its input is a U.S. state name or abbreviation. It normalizes the input to the standard two-leter postal service abbreviation for the given state.

class localflavor.us.forms.USStateSelect(attrs=None)[source]

A Select widget that uses a list of U.S. states/territories as its choices.

class localflavor.us.forms.USZipCodeField(max_length=None, min_length=None, *args, **kwargs)[source]

” A form field that validates input as a U.S. ZIP code. Valid formats are XXXXX or XXXXX-XXXX.

Models

class localflavor.us.models.PhoneNumberField(*args, **kwargs)[source]

A CharField that checks that the value is a valid U.S.A.-style phone number (in the format XXX-XXX-XXXX).

class localflavor.us.models.USPostalCodeField(*args, **kwargs)[source]

” A model field that forms represent as a forms.USPSSelect field and stores the two-letter U.S Postal Service abbreviation in the database.

class localflavor.us.models.USStateField(*args, **kwargs)[source]

A model field that forms represent as a forms.USStateField field and stores the two-letter U.S. state abbreviation in the database.

Data

localflavor.us.us_states.CONTIGUOUS_STATES = (('AL', 'Alabama'), ('AZ', 'Arizona'), ('AR', 'Arkansas'), ('CA', 'California'), ('CO', 'Colorado'), ('CT', 'Connecticut'), ('DE', 'Delaware'), ('DC', 'District of Columbia'), ('FL', 'Florida'), ('GA', 'Georgia'), ('ID', 'Idaho'), ('IL', 'Illinois'), ('IN', 'Indiana'), ('IA', 'Iowa'), ('KS', 'Kansas'), ('KY', 'Kentucky'), ('LA', 'Louisiana'), ('ME', 'Maine'), ('MD', 'Maryland'), ('MA', 'Massachusetts'), ('MI', 'Michigan'), ('MN', 'Minnesota'), ('MS', 'Mississippi'), ('MO', 'Missouri'), ('MT', 'Montana'), ('NE', 'Nebraska'), ('NV', 'Nevada'), ('NH', 'New Hampshire'), ('NJ', 'New Jersey'), ('NM', 'New Mexico'), ('NY', 'New York'), ('NC', 'North Carolina'), ('ND', 'North Dakota'), ('OH', 'Ohio'), ('OK', 'Oklahoma'), ('OR', 'Oregon'), ('PA', 'Pennsylvania'), ('RI', 'Rhode Island'), ('SC', 'South Carolina'), ('SD', 'South Dakota'), ('TN', 'Tennessee'), ('TX', 'Texas'), ('UT', 'Utah'), ('VT', 'Vermont'), ('VA', 'Virginia'), ('WA', 'Washington'), ('WV', 'West Virginia'), ('WI', 'Wisconsin'), ('WY', 'Wyoming'))

The 48 contiguous states, plus the District of Columbia.

localflavor.us.us_states.US_STATES = (('AL', 'Alabama'), ('AK', 'Alaska'), ('AZ', 'Arizona'), ('AR', 'Arkansas'), ('CA', 'California'), ('CO', 'Colorado'), ('CT', 'Connecticut'), ('DE', 'Delaware'), ('DC', 'District of Columbia'), ('FL', 'Florida'), ('GA', 'Georgia'), ('HI', 'Hawaii'), ('ID', 'Idaho'), ('IL', 'Illinois'), ('IN', 'Indiana'), ('IA', 'Iowa'), ('KS', 'Kansas'), ('KY', 'Kentucky'), ('LA', 'Louisiana'), ('ME', 'Maine'), ('MD', 'Maryland'), ('MA', 'Massachusetts'), ('MI', 'Michigan'), ('MN', 'Minnesota'), ('MS', 'Mississippi'), ('MO', 'Missouri'), ('MT', 'Montana'), ('NE', 'Nebraska'), ('NV', 'Nevada'), ('NH', 'New Hampshire'), ('NJ', 'New Jersey'), ('NM', 'New Mexico'), ('NY', 'New York'), ('NC', 'North Carolina'), ('ND', 'North Dakota'), ('OH', 'Ohio'), ('OK', 'Oklahoma'), ('OR', 'Oregon'), ('PA', 'Pennsylvania'), ('RI', 'Rhode Island'), ('SC', 'South Carolina'), ('SD', 'South Dakota'), ('TN', 'Tennessee'), ('TX', 'Texas'), ('UT', 'Utah'), ('VT', 'Vermont'), ('VA', 'Virginia'), ('WA', 'Washington'), ('WV', 'West Virginia'), ('WI', 'Wisconsin'), ('WY', 'Wyoming'))

All 50 states, plus the District of Columbia.

localflavor.us.us_states.US_TERRITORIES = (('AS', 'American Samoa'), ('GU', 'Guam'), ('MP', 'Northern Mariana Islands'), ('PR', 'Puerto Rico'), ('VI', 'Virgin Islands'))

Non-state territories.

localflavor.us.us_states.ARMED_FORCES_STATES = (('AA', 'Armed Forces Americas'), ('AE', 'Armed Forces Europe'), ('AP', 'Armed Forces Pacific'))

Military postal “states”. Note that ‘AE’ actually encompasses Europe, Canada, Africa and the Middle East.

localflavor.us.us_states.COFA_STATES = (('FM', 'Federated States of Micronesia'), ('MH', 'Marshall Islands'), ('PW', 'Palau'))

Non-US locations serviced by USPS (under Compact of Free Association).

localflavor.us.us_states.OBSOLETE_STATES = (('CM', 'Commonwealth of the Northern Mariana Islands'), ('CZ', 'Panama Canal Zone'), ('PI', 'Philippine Islands'), ('TT', 'Trust Territory of the Pacific Islands'))

Obsolete abbreviations (no longer US territories/USPS service, or code changed).

localflavor.us.us_states.STATE_CHOICES = (('AL', 'Alabama'), ('AK', 'Alaska'), ('AS', 'American Samoa'), ('AZ', 'Arizona'), ('AR', 'Arkansas'), ('AA', 'Armed Forces Americas'), ('AE', 'Armed Forces Europe'), ('AP', 'Armed Forces Pacific'), ('CA', 'California'), ('CO', 'Colorado'), ('CT', 'Connecticut'), ('DE', 'Delaware'), ('DC', 'District of Columbia'), ('FL', 'Florida'), ('GA', 'Georgia'), ('GU', 'Guam'), ('HI', 'Hawaii'), ('ID', 'Idaho'), ('IL', 'Illinois'), ('IN', 'Indiana'), ('IA', 'Iowa'), ('KS', 'Kansas'), ('KY', 'Kentucky'), ('LA', 'Louisiana'), ('ME', 'Maine'), ('MD', 'Maryland'), ('MA', 'Massachusetts'), ('MI', 'Michigan'), ('MN', 'Minnesota'), ('MS', 'Mississippi'), ('MO', 'Missouri'), ('MT', 'Montana'), ('NE', 'Nebraska'), ('NV', 'Nevada'), ('NH', 'New Hampshire'), ('NJ', 'New Jersey'), ('NM', 'New Mexico'), ('NY', 'New York'), ('NC', 'North Carolina'), ('ND', 'North Dakota'), ('MP', 'Northern Mariana Islands'), ('OH', 'Ohio'), ('OK', 'Oklahoma'), ('OR', 'Oregon'), ('PA', 'Pennsylvania'), ('PR', 'Puerto Rico'), ('RI', 'Rhode Island'), ('SC', 'South Carolina'), ('SD', 'South Dakota'), ('TN', 'Tennessee'), ('TX', 'Texas'), ('UT', 'Utah'), ('VT', 'Vermont'), ('VI', 'Virgin Islands'), ('VA', 'Virginia'), ('WA', 'Washington'), ('WV', 'West Virginia'), ('WI', 'Wisconsin'), ('WY', 'Wyoming'))

All US states and territories plus DC and military mail.

localflavor.us.us_states.USPS_CHOICES = (('AL', 'Alabama'), ('AK', 'Alaska'), ('AS', 'American Samoa'), ('AZ', 'Arizona'), ('AR', 'Arkansas'), ('AA', 'Armed Forces Americas'), ('AE', 'Armed Forces Europe'), ('AP', 'Armed Forces Pacific'), ('CA', 'California'), ('CO', 'Colorado'), ('CT', 'Connecticut'), ('DE', 'Delaware'), ('DC', 'District of Columbia'), ('FM', 'Federated States of Micronesia'), ('FL', 'Florida'), ('GA', 'Georgia'), ('GU', 'Guam'), ('HI', 'Hawaii'), ('ID', 'Idaho'), ('IL', 'Illinois'), ('IN', 'Indiana'), ('IA', 'Iowa'), ('KS', 'Kansas'), ('KY', 'Kentucky'), ('LA', 'Louisiana'), ('ME', 'Maine'), ('MH', 'Marshall Islands'), ('MD', 'Maryland'), ('MA', 'Massachusetts'), ('MI', 'Michigan'), ('MN', 'Minnesota'), ('MS', 'Mississippi'), ('MO', 'Missouri'), ('MT', 'Montana'), ('NE', 'Nebraska'), ('NV', 'Nevada'), ('NH', 'New Hampshire'), ('NJ', 'New Jersey'), ('NM', 'New Mexico'), ('NY', 'New York'), ('NC', 'North Carolina'), ('ND', 'North Dakota'), ('MP', 'Northern Mariana Islands'), ('OH', 'Ohio'), ('OK', 'Oklahoma'), ('OR', 'Oregon'), ('PW', 'Palau'), ('PA', 'Pennsylvania'), ('PR', 'Puerto Rico'), ('RI', 'Rhode Island'), ('SC', 'South Carolina'), ('SD', 'South Dakota'), ('TN', 'Tennessee'), ('TX', 'Texas'), ('UT', 'Utah'), ('VT', 'Vermont'), ('VI', 'Virgin Islands'), ('VA', 'Virginia'), ('WA', 'Washington'), ('WV', 'West Virginia'), ('WI', 'Wisconsin'), ('WY', 'Wyoming'))

All US Postal Service locations.

localflavor.us.us_states.STATES_NORMALIZED = {'gu': 'GU', 'nc': 'NC', 'co': 'CO', 'colorado': 'CO', 'neb': 'NE', 'ca': 'CA', 'n j': 'NJ', 'nmex': 'NM', 'w va': 'WV', 'ala': 'AL', 'colo': 'CO', 'tennessee': 'TN', 'wis': 'WI', 'ga': 'GA', 'deleware': 'DE', 'sdak': 'SD', 'nevada': 'NV', 'miss': 'MS', 'maine': 'ME', 'ct': 'CT', 'pr': 'PR', 'tn': 'TN', 'mississippi': 'MS', 'south dakota': 'SD', 'tx': 'TX', 'la': 'LA', 'new jersey': 'NJ', 'wyoming': 'WY', 'minnesota': 'MN', 'north carolina': 'NC', 'ariz': 'AZ', 'new york': 'NY', 'puerto rico': 'PR', 'indiana': 'IN', 'maryland': 'MD', 'louisiana': 'LA', 'guam': 'GU', 'calf': 'CA', 'iowa': 'IA', 'penn': 'PA', 'west virginia': 'WV', 'washington': 'WA', 'michigan': 'MI', 'de': 'DE', 'marinas islands of the pacific': 'MP', 'dc': 'DC', 'oregon': 'OR', 'virgina': 'VA', 'n m': 'NM', 'connecticut': 'CT', 'hi': 'HI', 'n h': 'NH', 'sd': 'SD', 'mich': 'MI', 'n d': 'ND', 'rhode island': 'RI', 'massachussetts': 'MA', 'me': 'ME', 'md': 'MD', 'marianas islands of the pacific': 'MP', 'georgia': 'GA', 'ma': 'MA', 'wash': 'WA', 'ut': 'UT', 'mo': 'MO', 'mn': 'MN', 'mi': 'MI', 'american samoa': 'AS', 'kentucky': 'KY', 'mt': 'MT', 'district of columbia': 'DC', 'del': 'DE', 'mp': 'MP', 'ms': 'MS', 'n mex': 'NM', 'fla': 'FL', 'ohio': 'OH', 'usvi': 'VI', 'texas': 'TX', 'wisc': 'WI', 'va': 'VA', 'north dakota': 'ND', 'minn': 'MN', 'nv': 'NV', 'vi': 'VI', 'ak': 'AK', 'al': 'AL', 'hawaii': 'HI', 'tex': 'TX', 'ind': 'IN', 'as': 'AS', 'ar': 'AR', 'vt': 'VT', 'il': 'IL', 'in': 'IN', 'ia': 'IA', 'territory of hawaii': 'HI', 'ark': 'AR', 'wv': 'WV', 'id': 'ID', 'conn': 'CT', 'nh': 'NH', 'virgin islands': 'VI', 'nj': 'NJ', 'az': 'AZ', 'nm': 'NM', 'pa': 'PA', 'oklahoma': 'OK', 'delaware': 'DE', 'nd': 'ND', 'ne': 'NE', 'illinois': 'IL', 'wva': 'WV', 'ny': 'NY', 'nebraska': 'NE', 'arkansas': 'AR', 'marianas islands': 'MP', 'nev': 'NV', 'new hampshire': 'NH', 'nebr': 'NE', 'calif': 'CA', 'ri': 'RI', 'idaho': 'ID', 'kans': 'KS', 'arizona': 'AZ', 'wisconsin': 'WI', 'wa': 'WA', 'utah': 'UT', 's dak': 'SD', 'kansas': 'KS', 'kan': 'KS', 'wi': 'WI', 'virginia': 'VA', 'wyo': 'WY', 'south carolina': 'SC', 'montana': 'MT', 'california': 'CA', 'massachusetts': 'MA', 'ore': 'OR', 'fl': 'FL', 'ky': 'KY', 'wy': 'WY', 'tenn': 'TN', 'us virgin islands': 'VI', 'vermont': 'VT', 'n dak': 'ND', 'ok': 'OK', 'northern mariana islands': 'MP', 'oh': 'OH', 'pennsylvania': 'PA', 'american samao': 'AS', 'ill': 'IL', 'oreg': 'OR', 'florida': 'FL', 'alaska': 'AK', 'ks': 'KS', 'viginia': 'VA', 'mont': 'MT', 'mass': 'MA', 'missouri': 'MO', 'sc': 'SC', 'alabama': 'AL', 'okla': 'OK', 'or': 'OR', 'new mexico': 'NM'}

Normalized versions of state names

Table Of Contents

Previous topic

Turkey (tr)

Next topic

Urguay (uy)

This Page