'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(u'error_messages') or {})
        error_messages[u'invalid'] = error_message
        kwargs[u'error_messages'] = error_messages
    super(RegexField, self).__init__(max_length, min_length, *args, **kwargs)
    self._set_regex(regex)
