entities_validation_svc/validators/validators.py

54 lines
1,002 B
Python
Raw Normal View History

2020-11-06 22:23:47 +01:00
import datetime
from schwifty import IBAN, BIC
def mandatory(field: str) -> bool:
return bool(field)
def empty(field: str) -> bool:
return not bool(field)
def iso_date(field: str) -> bool:
if not field:
return False
2020-11-06 22:23:47 +01:00
try:
datetime.datetime.strptime(field, "%Y-%m-%d")
return True
except ValueError:
return False
def valid_iban(field: str) -> bool:
if not field:
return False
if not type(field) == str:
return False
2020-11-06 22:23:47 +01:00
try:
IBAN(field)
return True
except ValueError:
return False
def valid_bic(field: str) -> bool:
if not field:
return False
if not type(field) == str:
return False
2020-11-06 22:23:47 +01:00
try:
BIC(field)
return True
except ValueError:
return False
2020-11-07 19:53:47 +01:00
2020-11-07 20:00:12 +01:00
2020-11-07 19:53:47 +01:00
def valid_money_amount(field: str) -> bool:
if not field:
return False
try:
float(field)
return True
except (ValueError, TypeError):
return False