Formify Docs

Trim

Strip leading and/or trailing whitespace

Trim

The trim formatter removes whitespace from the start, the end, or both sides of a value.

Options

OptionTypeDefaultDescription
mode"start" | "end" | "both""both"Which edges to trim.

Usage

validationSchema: {
  name: { format: { type: "trim", trigger: "onBlur", options: { mode: "start" } } },
  city: { format: { type: "trim", trigger: "onBlur", options: { mode: "end" } } },
  code: { format: { type: "trim", options: { mode: "both" } } },   // default
}

Examples

InputmodeResult
" hello ""both""hello"
" hello ""start""hello "
" hello ""end"" hello"

Things to know

  • Trigger defaults to "onChange" — most forms trim on "onBlur" so the value stays stable while typing.
  • The trim validator rejects edge whitespace instead of removing it; the normalize: "trim" preset always trims both sides on change.

On this page