Skip to content

Commit

Permalink
Fixed #737 -- Changed validators.isValidIPAddress4 to use a single re…
Browse files Browse the repository at this point in the history
…gex. Thanks, mattimustang

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1093 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Nov 6, 2005
1 parent 181ee4a commit 24f6666
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions django/core/validators.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ansi_datetime_re = re.compile('^%s %s$' % (_datere, _timere)) ansi_datetime_re = re.compile('^%s %s$' % (_datere, _timere))
email_re = re.compile(r'^[-\w.+]+@\w[\w.-]+$') email_re = re.compile(r'^[-\w.+]+@\w[\w.-]+$')
integer_re = re.compile(r'^-?\d+$') integer_re = re.compile(r'^-?\d+$')
ip4_re = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$') 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}$')
phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE) phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE)
slug_re = re.compile(r'^[-\w]+$') slug_re = re.compile(r'^[-\w]+$')
url_re = re.compile(r'^http://\S+$') url_re = re.compile(r'^http://\S+$')
Expand Down Expand Up @@ -93,11 +93,8 @@ def isCommaSeparatedEmailList(field_data, all_data):
raise ValidationError, _("Enter valid e-mail addresses separated by commas.") raise ValidationError, _("Enter valid e-mail addresses separated by commas.")


def isValidIPAddress4(field_data, all_data): def isValidIPAddress4(field_data, all_data):
if ip4_re.search(field_data): if not ip4_re.search(field_data):
valid_parts = [el for el in field_data.split('.') if 0 <= int(el) <= 255] raise ValidationError, _("Please enter a valid IP address.")
if len(valid_parts) == 4:
return
raise ValidationError, _("Please enter a valid IP address.")


def isNotEmpty(field_data, all_data): def isNotEmpty(field_data, all_data):
if field_data.strip() == '': if field_data.strip() == '':
Expand Down

0 comments on commit 24f6666

Please sign in to comment.