﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
1566	[patch] validator that validates if a specified number of validators pass	gary.wilson@…	Adrian Holovaty	"Explained in the docstring:

{{{
#!python
class SomeValidators:

    """"""Validates if `num_required` of given validators pass.
    
    This validator tries all given validators in order.  Once the
    `num_required` number of validators pass, validation passes without
    any further testing.  If `num_required` is not met, a validation error
    is raised with the given message.  The message is rather unspecific,
    so it's best to specify one on instantiation.
    """"""

    def __init__(self, num_required, validator_list=[], error_message=gettext_lazy(""This field is invalid."")):

    ..snip..
}}}

One use case is for validating passwords, where one might have something like...
{{{
#!python

hasLowercase = validators.MatchesRegularExpression('[a-z]', ""Password must contain at least one lowercase letter."")
hasUppercase = validators.MatchesRegularExpression('[A-Z]', ""Password must contain at least one uppercase letter."")
hasNumeric = validators.MatchesRegularExpression('[0-9]', ""Password must contain at least one number."")
strongPassword = validators.SomeValidators(num_required=2, validator_list=[hasLowercase, hasUppercase, hasNumeric],
                                           error_message=""Password must contain at least 2 of: lowercase, uppercase, and/or numeric characters."")

class AddUserForm(formfields.Manipulator):

    def __init__(self):
        self.fields = [
            formfields.PasswordField(field_name=""password"", length=15, maxlength=20, is_required=True, validator_list=[strongPassword]),
        ]
}}}

This also would mean that `validators.AnyValidator` now becomes a special case of `SomeValidators`.

patch coming..."	enhancement	closed	Validators	dev	normal	wontfix		gary.wilson@…	Unreviewed	1	0	0	0	0	0
