Formify Docs

Max Length

Enforce a maximum string length.

Max Length

Validates that a string is at most a given number of characters long.

Configuration

Config flagTypeDescription
maxLengthnumberMaximum number of characters.
maxLength[number, string]Tuple form — the length plus a custom message.

With useForm

const form = useForm({
  initialValues: { bio: '' },
  validationSchema: {
    bio: { maxLength: 160 },
  },
});

With a custom message:

bio: { maxLength: [160, 'At most {max} characters'] }

With the V builder

import { V } from 'formify-js';

V.maxLength(160);

Default message

ScenarioMessage
Value is longer than the maximumMust be at most 160 characters (the number reflects your value)

Examples

ValueRuleResult
'abc'maxLength: 3✅ Valid
'abcd'maxLength: 3❌ Invalid

Notes

  • The check is inclusive: a value of exactly 3 characters passes maxLength: 3.
  • Combine with minLength to define an exact allowed range.

On this page