Ticket #5709: fields.py.2.diff

File fields.py.2.diff, 1.2 KB (added by Nathan Hoover, 17 years ago)

patch

  • django/newforms/fields.py

     
    308308        raise ValidationError(ugettext(u'Enter a valid date/time.'))
    309309
    310310class RegexField(CharField):
    311     def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs):
     311    def __init__(self, regex, max_length=None, min_length=None, error_message=None, inverse=False, *args, **kwargs):
    312312        """
    313313        regex can be either a string or a compiled regular expression object.
    314314        error_message is an optional error message to use, if
     
    319319            regex = re.compile(regex)
    320320        self.regex = regex
    321321        self.error_message = error_message or ugettext(u'Enter a valid value.')
     322        self.inverse = inverse
    322323
    323324    def clean(self, value):
    324325        """
     
    328329        value = super(RegexField, self).clean(value)
    329330        if value == u'':
    330331            return value
    331         if not self.regex.search(value):
     332        if (self.regex.search(value) is None) != self.inverse:
    332333            raise ValidationError(self.error_message)
    333334        return value
    334335
Back to Top