diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2006-09-22 03:42:31 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2006-09-22 03:42:31 +0000 |
| commit | 14be60c4cb68ccd3062fc241ff2b9947fb010b98 (patch) | |
| tree | 7c53072de54306c13ad2792ab0c7b1d24286064c /django/core | |
| parent | 084d618519b20e12526a9de54ba8ed62ea7959ac (diff) | |
Fixed #2760 -- Fixed validation of negative float amounts in forms. Thanks,
James Bennett and Eddy Mulyono.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3788 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
| -rw-r--r-- | django/core/validators.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/django/core/validators.py b/django/core/validators.py index 6a8418848b..03590a456b 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -351,10 +351,12 @@ class IsValidFloat(object): float(data) except ValueError: raise ValidationError, gettext("Please enter a valid decimal number.") - if len(data) > (self.max_digits + 1): + # Negative floats require more space to input. + max_allowed_length = data.startswith('-') and (self.max_digits + 2) or (self.max_digits + 1) + if len(data) > max_allowed_length: 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)): + if (not '.' in data and len(data) > (self.max_allowed_length - 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: |
