Skip to content

Commit

Permalink
docs: Improves docs on the regex-rule
Browse files Browse the repository at this point in the history
Closes pyeve#389.
  • Loading branch information
funkyfuture committed Jun 11, 2018
1 parent 9e3e044 commit 3f1c0a1
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions docs/validation-rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -522,12 +522,17 @@ might be provided by the datastore, but should not writable.

regex
-----
Validation will fail if field value does not match the provided regular
expression. It is only tested on string values.
The validation will fail if the field's value does not match the provided
regular expression. It is only tested on string values.

.. doctest::

>>> schema = {'email': {'type': 'string', 'regex': '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'}}
>>> schema = {
... 'email': {
... 'type': 'string',
... 'regex': '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'
... }
... }
>>> document = {'email': 'john@example.com'}
>>> v.validate(document, schema)
True
Expand All @@ -540,8 +545,16 @@ expression. It is only tested on string values.
{'email': ["value does not match regex '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$'"]}

For details on regular expression syntax, see the documentation on the standard
library's :mod:`re`-module. Mind that you can set flags as part of the
expression, look for ``(?aiLmsux)`` in that document.
library's :mod:`re`-module.

.. hint::

Mind that one can set behavioural flags as part of the expression which is
equivalent to passing ``flags`` to the :func:`re.compile` function for
example. So, the constraint ``'(?i)holy grail'`` includes the equivalent
of the :obj:`re.I` flag and matches any string that includes 'holy grail'
or any variant of it with upper-case glyphs. Look for ``(?aiLmsux)`` in the
mentioned library documentation for a description there.

.. versionadded:: 0.7

Expand Down

0 comments on commit 3f1c0a1

Please sign in to comment.