Creating an Archetypes validator

Archetypes validators are used in the schema definition for a field. Default validators include isEmail, isURL, etc.

This is how to create a new validator:

First, the validator has to be registered with Archetypes, or zope will complain at startup and ignore the validator. So add something like this in the of the product:

from Products.validation import validation
from validators import SamePasswordValidator
Next, the source code for the validator (
from Products.validation.interfaces import ivalidator

class SamePasswordValidator:
__implements__ = (ivalidator,)

def __init__(self, name): = name

def __call__(self, value, *args, **kwargs):
instance = kwargs.get('instance', None)
req = kwargs['REQUEST']
pass1 = req.form.get('password', None)
if pass1 <> value:
return """Validation failed: You need to enter the password twice."""