X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/2f7a76a00f2bcae2f67459b7fd86806278ef9b66..954c1ed70e4dd2181d697c23de778756e5dd3e19:/validators.py?ds=inline diff --git a/validators.py b/validators.py index 637dba8..e4c32d0 100644 --- a/validators.py +++ b/validators.py @@ -1,5 +1,7 @@ from django.utils.translation import ugettext_lazy as _ from django.core.validators import RegexValidator +from django.core.exceptions import ValidationError +from django.utils import simplejson as json import re @@ -28,3 +30,10 @@ class URLLinkValidator(RegexValidator): r'|)' # also allow internal links r'(?:/?|[/?#]?\S+)$', re.IGNORECASE) message = _(u'Enter a valid absolute or relative redirect target') + + +def json_validator(value): + try: + json.loads(value) + except: + raise ValidationError(u'\'%s\' is not valid JSON' % value) \ No newline at end of file