from django.core import validators from django.utils import six from django.utils.deconstruct import deconstructible from django.utils.translation import ugettext_lazy as _ @deconstructible class HandleValidator(validators.RegexValidator): regex = r'^[A-Z]+[0-9]+(-[A-Z]+)' message = _( 'Enter a valid handle (all uppercase)' ) flags = re.ASCII if six.PY3 else 0