summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-06-19 01:09:00 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-06-19 01:09:00 +0000
commitc0ea3284d705a5d66c8aff372a5e33b15dce56e7 (patch)
tree38fc990ed575efa7c8cd337f368b0b698ca5ae39
parentc256dcd04bb0edcab93b99cee62b29df1cd6b046 (diff)
Fixed #1088 - Correctly detect when a float with too many digits before the
decimal point is passed in. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3142 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/validators.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/django/core/validators.py b/django/core/validators.py
index f09751e58d..f98589578e 100644
--- a/django/core/validators.py
+++ b/django/core/validators.py
@@ -355,6 +355,9 @@ class IsValidFloat(object):
if len(data) > (self.max_digits + 1):
raise ValidationError, ngettext("Please enter a valid decimal number with at most %s total digit.",
"Please enter a valid decimal number with at most %s total digits.", self.max_digits) % self.max_digits
+ if (not '.' in data and len(data) > (self.max_digits - self.decimal_places)) or ('.' in data and len(data) > (self.max_digits - (self.decimal_places - len(data.split('.')[1])) + 1)):
+ raise ValidationError, ngettext( "Please enter a valid decimal number with a whole part of at most %s digit.",
+ "Please enter a valid decimal number with a whole part of at most %s digits.", str(self.max_digits-self.decimal_places)) % str(self.max_digits-self.decimal_places)
if '.' in data and len(data.split('.')[1]) > self.decimal_places:
raise ValidationError, ngettext("Please enter a valid decimal number with at most %s decimal place.",
"Please enter a valid decimal number with at most %s decimal places.", self.decimal_places) % self.decimal_places