Ticket #13511: 13511-regexvalidator2.diff
File 13511-regexvalidator2.diff, 2.0 KB (added by , 13 years ago) |
---|
-
docs/ref/validators.txt
60 60 61 61 ``RegexValidator`` 62 62 ------------------ 63 .. class:: RegexValidator( regex, [message=None, code=None])63 .. class:: RegexValidator([regex=None, message=None, code=None]) 64 64 65 65 .. attribute:: regex 66 66 67 67 The regular expression pattern to search for the provided ``value``, 68 68 or a pre-compiled regular expression. Raises a 69 69 :exc:`~django.core.exceptions.ValidationError` with :attr:`.message` 70 and :attr:`.code` if no match is found. 70 and :attr:`.code` if no match is found. Matches any string (including 71 the empty string) if set to ``None``. 71 72 72 73 .. attribute:: message 73 74 -
tests/modeltests/validators/tests.py
112 112 (BaseValidator(True), True, None), 113 113 (BaseValidator(True), False, ValidationError), 114 114 115 (RegexValidator(), '', None), 116 (RegexValidator(), 'x1x2', None), 117 (RegexValidator('[0-9]+'), 'xxxxxx', ValidationError), 118 (RegexValidator('[0-9]+'), '1234', None), 119 (RegexValidator(re.compile('[0-9]+')), '1234', None), 115 120 (RegexValidator('.*'), '', None), 116 121 (RegexValidator(re.compile('.*')), '', None), 117 122 (RegexValidator('.*'), 'xxxxx', None), -
django/core/validators.py
29 29 if code is not None: 30 30 self.code = code 31 31 32 # compile the regex if it was not passed pre-compiled 32 33 if isinstance(self.regex, basestring): 33 self.regex = re.compile( regex)34 self.regex = re.compile(self.regex) 34 35 35 36 def __call__(self, value): 36 37 """