add function to validate money fields
This commit is contained in:
parent
c859a735ee
commit
652d1445a8
2 changed files with 19 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
||||||
from validators import mandatory, empty, iso_date, valid_iban, valid_bic
|
from validators import mandatory, empty, iso_date, valid_iban, valid_bic, valid_money_amount
|
||||||
|
|
||||||
|
|
||||||
def test_mandatory():
|
def test_mandatory():
|
||||||
|
@ -48,3 +48,12 @@ def test_valid_bic():
|
||||||
assert valid_bic("PBNKDEFFXXX".split()) == False
|
assert valid_bic("PBNKDEFFXXX".split()) == False
|
||||||
|
|
||||||
|
|
||||||
|
def test_valid_money_amount():
|
||||||
|
assert valid_money_amount(None) == False
|
||||||
|
assert valid_money_amount("") == False
|
||||||
|
assert valid_money_amount("0,00") == False
|
||||||
|
assert valid_money_amount("13,37") == False
|
||||||
|
assert valid_money_amount("0") == True
|
||||||
|
assert valid_money_amount("0.00") == True
|
||||||
|
assert valid_money_amount("13") == True
|
||||||
|
assert valid_money_amount("13.37") == True
|
|
@ -42,3 +42,12 @@ def valid_bic(field: str) -> bool:
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def valid_money_amount(field: str) -> bool:
|
||||||
|
if not field:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
float(field)
|
||||||
|
return True
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return False
|
Loading…
Reference in a new issue