Formify Docs

Array Length

Enforce a minimum or maximum item count on array fields

Array Length

The arrayLength rule validates that an array field — for example from <FieldArray> or a checkbox group — has at least min items and at most max items. An empty array fails the rule even without an explicit min.

Configuration

Config flagTypeDescription
arrayLength{ min?: number, max?: number, message?: string }Item count bounds. Omitting max applies the minimum only.
validationSchema: {
  tags: { arrayLength: { min: 1, max: 5 } },
}

With a custom message:

tags: { arrayLength: { min: 1, max: 5, message: "Choose 1 to 5 tags" } }

V builder

import { V } from "formify-js";

V.arrayLength(1, 5)
V.arrayLength(1)               // minimum only
V.arrayLength(1, 5, "Choose 1 to 5 tags")

Default message

The default message reflects your bounds, e.g. Must have at least 1 item or Must have at most 5 items.

Examples

ValueRuleResult
[]{ min: 1, max: 5 }❌ Invalid (empty)
["a"]{ min: 1, max: 5 }✅ Valid
["a", "b", "c", "d", "e", "f"]{ min: 1, max: 5 }❌ Invalid

Things to know

  • Both bounds are inclusive.
  • An empty array fails even when only max is set — combine with per-item validation inside <FieldArray> for full control over each entry.

On this page