1
0
mirror of https://github.com/django/django.git synced 2025-10-25 22:56:12 +00:00

Fixed #264 -- Added django.core.validators.isValidIPAddress4. Thanks, Hugo and Simon

git-svn-id: http://code.djangoproject.com/svn/django/trunk@671 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty
2005-09-23 02:02:15 +00:00
parent 36fc73a45b
commit 3d426607a8
2 changed files with 19 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ ansi_time_re = re.compile('^%s$' % _timere)
ansi_datetime_re = re.compile('^%s %s$' % (_datere, _timere))
email_re = re.compile(r'^[-\w.+]+@\w[\w.-]+$')
integer_re = re.compile(r'^-?\d+$')
ip4_re = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$')
phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE)
url_re = re.compile(r'^http://\S+$')
@@ -85,6 +86,13 @@ def isCommaSeparatedEmailList(field_data, all_data):
except ValidationError:
raise ValidationError, "Enter valid e-mail addresses separated by commas."
def isValidIPAddress4(field_data, all_data):
if ip4_re.search(field_data):
valid_parts = [el for el in field_data.split('.') if 0 <= int(el) <= 255]
if len(valid_parts) == 4:
return
raise validators.ValidationError, "Please enter a valid IP address."
def isNotEmpty(field_data, all_data):
if field_data.strip() == '':
raise ValidationError, "Empty values are not allowed here."