entities_validation_svc/validation_functions.py
2020-12-04 21:18:19 +01:00

30 lines
No EOL
717 B
Python

from schwifty import IBAN, BIC
import datetime
def valid_iban(field, value, error):
try:
IBAN(value)
return True
except ValueError:
error(field, 'not a valid IBAN')
def valid_bic(field, value, error):
try:
BIC(value)
return True
except ValueError:
error(field, 'not a valid BIC')
def iso_date(field, value, error):
try:
datetime.datetime.strptime(value, "%Y-%m-%d")
return True
except ValueError:
error(field, 'not a valid ISO 8601 date')
def valid_money_amount(field, value, error):
try:
float(value)
return True
except (ValueError, TypeError):
error(field, 'not a valid money value')