Ticket #5709: fields.py.diff
File fields.py.diff, 1.2 KB (added by , 17 years ago) |
---|
-
django/newforms/fields.py
308 308 raise ValidationError(ugettext(u'Enter a valid date/time.')) 309 309 310 310 class RegexField(CharField): 311 def __init__(self, regex, max_length=None, min_length=None, error_message=None, *args, **kwargs):311 def __init__(self, regex, inverse=False, max_length=None, min_length=None, error_message=None, *args, **kwargs): 312 312 """ 313 313 regex can be either a string or a compiled regular expression object. 314 314 error_message is an optional error message to use, if … … 319 319 regex = re.compile(regex) 320 320 self.regex = regex 321 321 self.error_message = error_message or ugettext(u'Enter a valid value.') 322 self.inverse = inverse 322 323 323 324 def clean(self, value): 324 325 """ … … 328 329 value = super(RegexField, self).clean(value) 329 330 if value == u'': 330 331 return value 331 if not self.regex.search(value):332 if (self.regex.search(value) == None) != self.inverse: 332 333 raise ValidationError(self.error_message) 333 334 return value 334 335