Regex

Invalid if the value doesn't match the regular expression regex .

The regular expression can be a compiled re object, or a string which will be compiled for you.

Use strip=True if you want to strip the value before validation, and as a form of conversion (often useful).

Examples:

>>> cap = Regex(r'^[A-Z]+$')
>>> cap.to_python('ABC')
'ABC'

Note that .from_python() calls (in general) do not validate the input:

>>> cap.from_python('abc')
'abc'
>>> cap(accept_python=False).from_python('abc')
Traceback (most recent call last):
  ...
Invalid: The input is not valid
>>> cap.to_python(1)
Traceback (most recent call last):
  ...
Invalid: The input must be a string (not a <type 'int'>: 1)
>>> Regex(r'^[A-Z]+$', strip=True).to_python('  ABC  ')
'ABC'
>>> Regex(r'this', regexOps=('I',)).to_python('THIS')
'THIS'

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
invalid:
The input is not valid
noneType:
The input must be a string (not None)

Attributes

a gettextargs

{}

a regexOps

()

a strip

False

a use_builtins_gettext

True

a regex

None

a accept_python

True

a __singletonmethods__

('to_python', 'from_python', 'message', 'all_messages', 'subvalidators')

a declarative_count

18

a __unpackargs__

('regex',)

a compound

False

a not_empty

False

a __mutableattributes__

()

a repeating

False

Methods

f __initargs__(self, new_attrs) ...

f __call__(self, *args, **kw) ...

f __classinit__(cls, new_attrs) ...

f __sourcerepr__(self, source, binding=None) ...

f __classsourcerepr__(cls, source, binding=None) ...

f __init__(self, *args, **kw) ...

f validate_python(self, value, state) ...

See the source for more information.