---
title: maxSize
description: Creates a max size validation action.
source: /actions/maxSize/maxSize.ts
contributors:
  - fabian-hiller
---

import { ApiList, Property } from '~/components';
import { properties } from './properties';

# maxSize

Creates a max size validation action.

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

## Generics

- `TInput` <Property {...properties.TInput} />
- `TRequirement` <Property {...properties.TRequirement} />
- `TMessage` <Property {...properties.TMessage} />

## Parameters

- `requirement` <Property {...properties.requirement} />
- `message` <Property {...properties.message} />

### Explanation

With `maxSize` 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` <Property {...properties.Action} />

## Examples

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

### Blob size schema

Schema to validate a blob with a maximum size of 10 MB.

```ts
const BlobSchema = v.pipe(
  v.blob(),
  v.maxSize(10 * 1024 * 1024, 'The blob must not exceed 10 MB.')
);
```

### Set size schema

Schema to validate a set with a maximum of 8 numbers.

```ts
const SetSchema = v.pipe(
  v.set(number()),
  v.maxSize(8, 'The set must not exceed 8 numbers.')
);
```

## Related

The following APIs can be combined with `maxSize`.

### Schemas

<ApiList
  items={['any', 'blob', 'custom', 'file', 'instance', 'map', 'set', 'unknown']}
/>

### Methods

<ApiList items={['pipe']} />

### Utils

<ApiList items={['isOfKind', 'isOfType']} />
