summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorHonza Král <honza.kral@gmail.com>2009-07-05 13:29:08 +0000
committerHonza Král <honza.kral@gmail.com>2009-07-05 13:29:08 +0000
commitc1093ca87fbcb57c47aeb323edacfadead859cb2 (patch)
tree0943a471514380216ecc3c69e0129745eeb9d94d /django/core
parentcb7d3f2a0e16c974f84df8b62d24a774220f7507 (diff)
[soc2009/model-validation] SlugField and IPAddressField now use validators.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11191 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
-rw-r--r--django/core/validators.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/django/core/validators.py b/django/core/validators.py
index 1426c1c903..6758a387b0 100644
--- a/django/core/validators.py
+++ b/django/core/validators.py
@@ -22,6 +22,24 @@ def validate_email(value):
if not email_re.search(smart_unicode(value)):
raise ValidationError(_(u'Enter a valid e-mail address.'), code='invalid')
+slug_re = re.compile(r'^[-\w]+$')
+
+def validate_slug(value):
+ if not slug_re.search(smart_unicode(value)):
+ raise ValidationError(
+ _(u"Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens."),
+ code='invalid'
+ )
+
+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}$')
+
+def validate_ipv4_address(value):
+ if not ipv4_re.search(smart_unicode(value)):
+ raise ValidationError(
+ _(u'Enter a valid IPv4 address.'),
+ code="invalid"
+ )
+
class MaxValueValidator(object):
def __init__(self, max_value):
self.max_value = max_value