---
title: cuid2
description: Creates a Cuid2 validation action.
source: /actions/cuid2/cuid2.ts
contributors:
  - fabian-hiller
---

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

# cuid2

Creates a [Cuid2](https://github.com/paralleldrive/cuid2) validation action.

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

## Generics

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

## Parameters

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

### Explanation

With `cuid2` you can validate the formatting of a string. If the input is not an Cuid2, you can use `message` to customize the error message.

> Since Cuid2s are not limited to a fixed length, it is recommended to combine `cuid2` with <Link href="../length/">`length`</Link> to ensure the correct length.

## Returns

- `Action` <Property {...properties.Action} />

## Examples

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

### Cuid2 schema

Schema to validate an Cuid2.

```ts
const Cuid2Schema = v.pipe(
  v.string(),
  v.cuid2('The Cuid2 is badly formatted.'),
  v.length(10, 'The Cuid2 must be 10 characters long.')
);
```

## Related

The following APIs can be combined with `cuid2`.

### Schemas

<ApiList items={['any', 'custom', 'string']} />

### Methods

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

### Utils

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