---
title: nonEmpty
description: Creates a non-empty validation action.
source: /actions/nonEmpty/nonEmpty.ts
contributors:
  - fabian-hiller
---

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

# nonEmpty

Creates a non-empty validation action.

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

## Generics

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

## Parameters

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

### Explanation

With `nonEmpty` you can validate that a string or array is non-empty. If the input is empty, you can use `message` to customize the error message.

## Returns

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

## Examples

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

### String schema

Schema to validate that a string is non-empty.

```ts
const StringSchema = v.pipe(
  v.string(),
  v.nonEmpty('The string should contain at least one character.')
);
```

### Array schema

Schema to validate that an array is non-empty.

```ts
const ArraySchema = v.pipe(
  v.array(v.number()),
  v.nonEmpty('The array should contain at least one item.')
);
```

## Related

The following APIs can be combined with `nonEmpty`.

### Schemas

<ApiList
  items={['any', 'array', 'custom', 'instance', 'string', 'tuple', 'unknown']}
/>

### Methods

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

### Utils

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