diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-09-16 11:38:32 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-09-16 11:38:32 +0000 |
| commit | c012b8964e596423b68f4ec4b1b57253cf0ae7b0 (patch) | |
| tree | e55a21580181508584b77561f2acd12a0278dd1b /django/newforms/fields.py | |
| parent | c694587ebbf7a45d3e6f91f5bfc4e81001c03d97 (diff) | |
Fixed #4067 -- Fixed validation of IPAddressFields in newforms. Thanks to neils and the team in the Copenhagen sprint group.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6357 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/fields.py')
| -rw-r--r-- | django/newforms/fields.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/django/newforms/fields.py b/django/newforms/fields.py index 8fb1d4f392..a39987e1b5 100644 --- a/django/newforms/fields.py +++ b/django/newforms/fields.py @@ -26,7 +26,7 @@ __all__ = ( 'RegexField', 'EmailField', 'FileField', 'ImageField', 'URLField', 'BooleanField', 'ChoiceField', 'NullBooleanField', 'MultipleChoiceField', 'ComboField', 'MultiValueField', 'FloatField', 'DecimalField', - 'SplitDateTimeField', + 'SplitDateTimeField', 'IPAddressField', ) # These values, if given to to_python(), will trigger the self.required check. @@ -635,3 +635,11 @@ class SplitDateTimeField(MultiValueField): raise ValidationError(ugettext(u'Enter a valid time.')) return datetime.datetime.combine(*data_list) return None + +ipv4_re = re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$') + +class IPAddressField(RegexField): + def __init__(self, *args, **kwargs): + RegexField.__init__(self, ipv4_re, + error_message=ugettext(u'Enter a valid IPv4 address.'), + *args, **kwargs) |
