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
| Option | Type | Default | Description |
|---|---|---|---|
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
| Input | mode | Result |
|---|---|---|
" 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
trimvalidator rejects edge whitespace instead of removing it; thenormalize: "trim"preset always trims both sides on change.