Skip to content

Commit

Permalink
Merge pull request #694 from if4lcon/4.0
Browse files Browse the repository at this point in the history
numeric validation rule to accepts floats
  • Loading branch information
josephmancuso committed Jul 27, 2022
2 parents 65ef7cf + d024145 commit 9664b4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/masonite/validation/Validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,10 @@ class numeric(BaseValidation):
def passes(self, attribute, key, dictionary):
if isinstance(attribute, list):
for value in attribute:
if not str(value).isdigit():
if not str(value).replace(".", "", 1).isdigit():
return False
else:
return str(attribute).isdigit()
return str(attribute).replace(".", "", 1).isdigit()

return True

Expand Down
8 changes: 8 additions & 0 deletions tests/features/validation/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,18 @@ def test_numeric(self):

self.assertEqual(len(validate), 0)

validate = Validator().validate({"test": 1.9}, numeric(["test"]))

self.assertEqual(len(validate), 0)

validate = Validator().validate({"test": "hey"}, numeric(["test"]))

self.assertEqual(validate.all(), {"test": ["The test must be a numeric."]})

validate = Validator().validate({"test": '1..9'}, numeric(["test"]))

self.assertEqual(validate.all(), {"test": ["The test must be a numeric."]})

def test_several_tests(self):
validate = Validator().validate(
{"test": "hey"}, required(["notin"]), numeric(["notin"])
Expand Down

0 comments on commit 9664b4b

Please sign in to comment.