This module provides the built-in validators used by the fields and a helper to create your own validator factory ( as_validator() ).
The validators used by Formular are simple functions, which take the form, an initial value and the value which should be validated. If the validation is successful the function returns True otherwise False.
Error messages are handled by the field itself and are not created by the validator, as they may differ in the context of the field.
If you want to use your own validators on an exisitng field type checkout the formular.fields.Field.register_as_validator() documentation.
Validates if the value is a valid e-mail address.
Warning
This function does not implement rfc2822 completely.
New in version 0.2.
If you want to create your own field type, you will have to create a validator factory. Such a factory takes the initial value and returns a callable which takes the form and the value which should be validated. This way the field does not have to store the initial values.
The easiest way to create a validator factory, which can be put into formular.fields.Field.validator_factories, is to use as_validator().
Given a function like:
def required(form, is_required, value):
return bool(value) if is_required else True
as_validator() returns a factory function:
>>> required_factory(required)
>>> required_factory(True)(form, u"")
False
>>> required_factory(False)(form, u"")
If you do not care about the original function you can use as_validator() to decorate the function.