diff options
| author | Edward D'Souza <edward.dsouza@polarmobile.com> | 2017-05-23 19:49:44 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-05-25 14:09:47 -0400 |
| commit | ed9bc4e576d57863c10d839ee43fb2febf04fb84 (patch) | |
| tree | 011f3647a0d7c740efe61ce73c6c796c4c1f8897 | |
| parent | 1b5b3710f16450eca49fb11b41a242816857a454 (diff) | |
Made RegexValidator's inverse_match logic clearer.
| -rw-r--r-- | django/core/validators.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/django/core/validators.py b/django/core/validators.py index e454ca213b..390c400ce8 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -51,10 +51,12 @@ class RegexValidator: def __call__(self, value): """ - Validate that the input contains a match for the regular expression - if inverse_match is False, otherwise raise ValidationError. + Validate that the input contains (or does *not* contain, if + inverse_match is True) a match for the regular expression. """ - if not (self.inverse_match is not bool(self.regex.search(str(value)))): + regex_matches = bool(self.regex.search(str(value))) + invalid_input = regex_matches if self.inverse_match else not regex_matches + if invalid_input: raise ValidationError(self.message, code=self.code) def __eq__(self, other): |
