Skip to main content

Country-specific validation helpers, ported from Django Localflavor

Project description

https://travis-ci.com/anka-sirota/localflavor.svg?branch=master

localflavor

This package is a derivative of django-localflavor and a work in progress. This package does not depend on Django, and currently only contains postal codes validators, lists of country states and provinces and calling (dial in) codes.

Installation

pip install localflavor

Example usage

Postal code validation

>>> from localflavor.generic.validators import validate_country_postcode
>>> validate_country_postcode('1000AA', 'NL')
'1000 AA'
>>> validate_country_postcode('0888', 'US')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "../localflavor/generic/validators.py", line 453, in validate_country_postcode
    return validator.clean(value)
  File "../localflavor/base.py", line 71, in clean
    value = super(RegexValidator, self).clean(value)
  File "../localflavor/base.py", line 48, in clean
    raise ValidationError(self.error_messages['invalid'])
localflavor.exceptions.ValidationError: Enter a postal code in the format XXXXX or XXXXX-XXXX.

Calling codes

>>> from localflavor.generic.countries.calling_codes import CALLING_CODES
>>> CALLING_CODES.get('US')
'+1'
>>> CALLING_CODES.get('RU')
'+7'
>>> CALLING_CODES.get('NL')
'+31'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for localflavor, version 1.4
Filename, size File type Python version Upload date Hashes
Filename, size localflavor-1.4-py3-none-any.whl (120.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size localflavor-1.4.tar.gz (78.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page