Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #737 -- Changed validators.isValidIPAddress4 to use a single re…

…gex. Thanks, mattimustang

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1093 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 24f666656f482d567827f148a024b3c59fb5e4f0 1 parent 181ee4a
Adrian Holovaty authored November 06, 2005

Showing 1 changed file with 3 additions and 6 deletions. Show diff stats Hide diff stats

  1. 9  django/core/validators.py
9  django/core/validators.py
@@ -19,7 +19,7 @@
19 19
 ansi_datetime_re = re.compile('^%s %s$' % (_datere, _timere))
20 20
 email_re = re.compile(r'^[-\w.+]+@\w[\w.-]+$')
21 21
 integer_re = re.compile(r'^-?\d+$')
22  
-ip4_re = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$')
  22
+ip4_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}$')
23 23
 phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE)
24 24
 slug_re = re.compile(r'^[-\w]+$')
25 25
 url_re = re.compile(r'^http://\S+$')
@@ -93,11 +93,8 @@ def isCommaSeparatedEmailList(field_data, all_data):
93 93
             raise ValidationError, _("Enter valid e-mail addresses separated by commas.")
94 94
 
95 95
 def isValidIPAddress4(field_data, all_data):
96  
-    if ip4_re.search(field_data):
97  
-        valid_parts = [el for el in field_data.split('.') if 0 <= int(el) <= 255]
98  
-        if len(valid_parts) == 4:
99  
-            return
100  
-    raise ValidationError, _("Please enter a valid IP address.")
  96
+    if not ip4_re.search(field_data):
  97
+        raise ValidationError, _("Please enter a valid IP address.")
101 98
 
102 99
 def isNotEmpty(field_data, all_data):
103 100
     if field_data.strip() == '':

0 notes on commit 24f6666

Please sign in to comment.
Something went wrong with that request. Please try again.