mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #20784 -- Added inverse_match parameter to RegexValidator.
This commit is contained in:
parent
0d98422b13
commit
b102c27ff4
4 changed files with 29 additions and 6 deletions
|
@ -59,20 +59,22 @@ to, or in lieu of custom ``field.clean()`` methods.
|
|||
|
||||
``RegexValidator``
|
||||
------------------
|
||||
.. class:: RegexValidator([regex=None, message=None, code=None])
|
||||
.. class:: RegexValidator([regex=None, message=None, code=None, inverse_match=None])
|
||||
|
||||
:param regex: If not ``None``, overrides :attr:`regex`. Can be a regular
|
||||
expression string or a pre-compiled regular expression.
|
||||
:param message: If not ``None``, overrides :attr:`.message`.
|
||||
:param code: If not ``None``, overrides :attr:`code`.
|
||||
:param inverse_match: If not ``None``, overrides :attr:`inverse_match`.
|
||||
|
||||
.. attribute:: regex
|
||||
|
||||
The regular expression pattern to search for the provided ``value``,
|
||||
or a pre-compiled regular expression. Raises a
|
||||
:exc:`~django.core.exceptions.ValidationError` with :attr:`message`
|
||||
and :attr:`code` if no match is found. By default, matches any string
|
||||
(including an empty string).
|
||||
and :attr:`code` if :attr:`inverse_match` is ``False`` and a match is
|
||||
found, or if :attr:`inverse_match` is ``True`` and a match is not found.
|
||||
By default, matches any string (including an empty string).
|
||||
|
||||
.. attribute:: message
|
||||
|
||||
|
@ -85,6 +87,12 @@ to, or in lieu of custom ``field.clean()`` methods.
|
|||
The error code used by :exc:`~django.core.exceptions.ValidationError`
|
||||
if validation fails. Defaults to ``"invalid"``.
|
||||
|
||||
.. attribute:: inverse_match
|
||||
|
||||
.. versionadded:: 1.7
|
||||
|
||||
The match mode for :attr:`regex`. Defaults to ``False``.
|
||||
|
||||
``URLValidator``
|
||||
----------------
|
||||
.. class:: URLValidator([schemes=None, regex=None, message=None, code=None])
|
||||
|
|
|
@ -697,6 +697,12 @@ Tests
|
|||
Validators
|
||||
^^^^^^^^^^
|
||||
|
||||
* :class:`~django.core.validators.RegexValidator` now accepts an optional
|
||||
Boolean :attr:`~django.core.validators.RegexValidator.inverse_match` argument
|
||||
which determines if the :exc:`~django.core.exceptions.ValidationError` should
|
||||
be raised when the regular expression pattern matches (``True``) or does not
|
||||
match (``False``, by default) the provided ``value``.
|
||||
|
||||
* :class:`~django.core.validators.URLValidator` now accepts an optional
|
||||
``schemes`` argument which allows customization of the accepted URI schemes
|
||||
(instead of the defaults ``http(s)`` and ``ftp(s)``).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue