1 from django.utils.translation import ugettext_lazy as _
2 from django.core.validators import RegexValidator
6 class RedirectValidator(RegexValidator):
7 """Based loosely on the URLValidator, but no option to verify_exists"""
9 r'^(?:https?://' # http:// or https://
10 r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?|' #domain...
11 r'localhost|' #localhost...
12 r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
13 r'(?::\d+)?' # optional port
17 message = _(u'Enter a valid absolute or relative redirect target')
20 class URLLinkValidator(RegexValidator):
21 """Based loosely on the URLValidator, but no option to verify_exists"""
23 r'^(?:https?://' # http:// or https://
24 r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?|' #domain...
25 r'localhost|' #localhost...
26 r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
27 r'(?::\d+)?' # optional port
28 r'|)' # also allow internal links
29 r'(?:/?|[/?#]?\S+)$', re.IGNORECASE)
30 message = _(u'Enter a valid absolute or relative redirect target')