'regex can be either a string or a compiled regular expression object.
error_message is an optional error message to use, if
\'Enter a valid value\' is too generic for you.'

def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs):

    if error_message:
        error_messages = (kwargs.get('error_messages') or {})
        error_messages['invalid'] = error_message
        kwargs['error_messages'] = error_messages
    super(RegexField, self).__init__(max_length, min_length, *args, **kwargs)
    if isinstance(regex, basestring):
        regex = re.compile(regex)
    self.regex = regex
    self.validators.append(validators.RegexValidator(regex=regex))
