country¶
- validators.country.calling_code(value: str, /)¶
Validates given calling code.
This performs country’s calling code validation.
Examples
>>> calling_code('+91') True >>> calling_code('-31') ValidationError(func=calling_code, args={'value': '-31'})
- Parameters:
value – Country’s calling code string to validate.
- Returns:
If value is a valid calling code. (ValidationError): If value is an invalid calling code.
- Return type:
(Literal[True])
- validators.country.country_code(value: str, /, *, iso_format: str = 'auto', ignore_case: bool = False)¶
Validates given country code.
This performs a case-sensitive [ISO 3166][1] country code validation.
[1]: https://www.iso.org/iso-3166-country-codes.html
Examples
>>> country_code('GB', iso_format='alpha3') ValidationError(func=country_code, args={'value': 'GB', 'iso_format': 'alpha3'}) >>> country_code('USA') True >>> country_code('840', iso_format='numeric') True >>> country_code('iN', iso_format='alpha2') ValidationError(func=country_code, args={'value': 'iN', 'iso_format': 'alpha2'}) >>> country_code('ZWE', iso_format='alpha3') True
- Parameters:
value – Country code string to validate.
iso_format – ISO format to be used. Available options are: auto, alpha2, alpha3 and numeric.
ignore_case – Enable/Disable case-sensitive matching.
- Returns:
If value is a valid country code. (ValidationError): If value is an invalid country code.
- Return type:
(Literal[True])
- validators.country.currency(value: str, /, *, skip_symbols: bool = True, ignore_case: bool = False)¶
Validates given currency code.
This performs [ISO 4217][1] currency code/symbol validation.
[1]: https://www.iso.org/iso-4217-currency-codes.html
Examples
>>> currency('USD') True >>> currency('ZWX') ValidationError(func=currency, args={'value': 'ZWX'})
- Parameters:
value – Currency code/symbol string to validate.
skip_symbols – Skip currency symbol validation.
ignore_case – Enable/Disable case-sensitive matching.
- Returns:
If value is a valid currency code. (ValidationError): If value is an invalid currency code.
- Return type:
(Literal[True])