> For the complete documentation index, see [llms.txt](https://www.strickland.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.strickland.io/composition/arrays-of-validators.md).

# Arrays of Validators

Values often need to be validated against multiple validators. This can be represented in Strickland by using arrays of validators with a top-level validator that operates over the array. The top-level validator can invoke the `validate` function to collect results from each validator and combine the results into a top-level validation result.

Here is a validator that validates every validator in an array, short-circuiting as soon as an invalid result is encountered.

```jsx
import validate from './strickland';

export default function every(validators) {
    return function validateEvery(value, context) {
        let result = {
            value,
            isValid: true
        };

        validators.every((validator) => {
            let validatorResult = validate(
                validator, value, context
            );

            result = {
                ...result,
                ...validatorResult,
                isValid: validatorResult.isValid
            };

            return result.isValid;
        });

        return result;
    }
}
```

The `every` validator uses the factory pattern, accepting an array of validators and returning a function to validate every one of the validators. Because validators can accept validation context, those must be accepted and passed through.

Here is how the `every` validator can be used.

```jsx
import validate, {every, required, minLength} from 'strickland';

const mustExistWithLength5 = every([
    required(),
    minLength(5)
]);

const result = validate(mustExistWithLength5, '1234', {
    message: 'Must have a length of at least 5'
});

/*
    result = {
        isValid: false,
        value: '1234',
        required: true,
        minLength: 5,
        length: 4
    }
 */
```

## Built-In Composition Validators

Strickland has a few built-in composition validators that operate over arrays of validators.

* [every](/composition/arrays-of-validators/every.md)
  * Returns a valid result if all validators are valid
  * Short-circuits upon the first invalid result
* [all](/composition/arrays-of-validators/all.md)
  * Returns a valid result if all validators are valid
  * Does not short-circuit, producing results for all validators
* [some](/composition/arrays-of-validators/some.md)
  * Returns a valid result if any validator is valid
  * Short-circuits upon the first valid result
