trimmed

Creates a trimmed validation action.

The difference between trimmed and trim is that trimmed only validates that a string has no leading or trailing whitespace, while trim removes it.

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

Generics

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

Examples

The following examples show how trimmed can be used.

Username schema

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

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

The following APIs can be combined with trimmed.

Schemas

Methods

Utils

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of @fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of @evilmartians
  • GitHub profile picture of @vasilii-kovalev
  • GitHub profile picture of @ruiaraujo012
  • GitHub profile picture of @hyunbinseo
  • GitHub profile picture of @nickytonline
  • GitHub profile picture of @kibertoad
  • GitHub profile picture of @caegdeveloper
  • GitHub profile picture of @Thanaen
  • GitHub profile picture of @ysknsid25
  • GitHub profile picture of @dslatkin