# size

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

Creates a size validation action.

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

## Generics

- `TInput` `extends SizeInput`
- `TRequirement` `extends number`
- `TMessage` `extends ErrorMessage<SizeIssue<TInput, TRequirement>> | undefined`

## Parameters

- `requirement` `TRequirement`
- `message` `TMessage`

### Explanation

With `size` you can validate the size of a map, set or blob. If the input does not match the `requirement`, you can use `message` to customize the error message.

## Returns

- `Action` `SizeAction<TInput, TRequirement, TMessage>`

## Examples

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

### Blob size schema

Schema to validate a blob with a size of 256 bytes.

```ts
const BlobSchema = v.pipe(
  v.blob(),
  v.size(256, 'The blob must be 256 bytes in size.')
);
```

### Set size schema

Schema to validate a set of 8 numbers.

```ts
const SetSchema = v.pipe(
  v.set(v.number()),
  v.size(8, 'The set must contain 8 numbers.')
);
```

## Related

The following APIs can be combined with `size`.

### Schemas

[`any`](/api/any.md), [`array`](/api/array.md), [`custom`](/api/custom.md), [`instance`](/api/instance.md), [`string`](/api/string.md), [`tuple`](/api/tuple.md), [`unknown`](/api/unknown.md)

### Methods

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

### Utils

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