# trimmed

> This document is the Markdown version of [valibot.dev/api/trimmed/](https://valibot.dev/api/trimmed/). For the complete documentation index, see [llms.txt](https://valibot.dev/llms.txt).

Creates a trimmed validation action.

> The difference between `trimmed` and [`trim`](/api/trim.md) is that `trimmed` only validates that a string has no leading or trailing whitespace, while [`trim`](/api/trim.md) removes it.

```ts
const Action = v.trimmed<TInput, TMessage>(message);
```

## Generics

- `TInput` `extends string`
- `TMessage` `extends ErrorMessage<TrimmedIssue<TInput>> | undefined`

## Parameters

- `message` `TMessage`

### Explanation

With `trimmed` you can validate that a string has no leading or trailing whitespace. If the input is not trimmed, you can use `message` to customize the error message.

## Returns

- `Action` `TrimmedAction<TInput, TMessage>`

## Examples

The following examples show how `trimmed` can be used.

### Username schema

Schema to validate that a username has no leading or trailing whitespace.

```ts
const UsernameSchema = v.pipe(
  v.string(),
  v.trimmed('The username must not start or end with whitespace.')
);
```

## Related

The following APIs can be combined with `trimmed`.

### Schemas

[`any`](/api/any.md), [`custom`](/api/custom.md), [`string`](/api/string.md)

### Methods

[`pipe`](/api/pipe.md)

### Utils

[`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md)
