# custom

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

Creates a custom schema.

> This schema function allows you to define a schema that matches a value based on a custom function. Use it whenever you need to define a schema that cannot be expressed using any of the other schema functions.

```ts
const Schema = v.custom<TInput, TMessage>(check, message);
```

## Generics

- `TInput` `extends any`
- `TMessage` `extends ErrorMessage<CustomIssue> | undefined = ErrorMessage<CustomIssue> | undefined`

## Parameters

- `check` `(input: unknown) => boolean`
- `message` `TMessage`

### Explanation

With `custom` you can validate the data type of the input. If the input does not match the validation of `check`, you can use `message` to customize the error message.

> Make sure that the validation in `check` matches the data type of `TInput`.

## Returns

- `Schema` `CustomSchema<TInput, TMessage>`

## Examples

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

### Pixel string schema

Schema to validate a pixel string.

```ts
const PixelStringSchema = v.custom<`${number}px`>((input) =>
  typeof input === 'string' ? /^\d+px$/.test(input) : false
);
```

## Related

The following APIs can be combined with `custom`.

### Schemas

[`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md)

### Methods

[`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`is`](/api/is.md), [`message`](/api/message.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pipe`](/api/pipe.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md)

### Actions

[`args`](/api/args.md), [`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`check`](/api/check.md), [`checkItems`](/api/checkItems.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`decimal`](/api/decimal.md), [`description`](/api/description.md), [`digits`](/api/digits.md), [`domain`](/api/domain.md), [`email`](/api/email.md), [`emoji`](/api/emoji.md), [`empty`](/api/empty.md), [`endsWith`](/api/endsWith.md), [`entries`](/api/entries.md), [`everyItem`](/api/everyItem.md), [`excludes`](/api/excludes.md), [`filterItems`](/api/filterItems.md), [`findItem`](/api/findItem.md), [`finite`](/api/finite.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.md), [`integer`](/api/integer.md), [`ip`](/api/ip.md), [`ipv4`](/api/ipv4.md), [`ipv6`](/api/ipv6.md), [`isbn`](/api/isbn.md), [`isrc`](/api/isrc.md), [`isoDate`](/api/isoDate.md), [`isoDateTime`](/api/isoDateTime.md), [`isoDateTimeSecond`](/api/isoDateTimeSecond.md), [`isoTime`](/api/isoTime.md), [`isoTimeSecond`](/api/isoTimeSecond.md), [`isoTimestamp`](/api/isoTimestamp.md), [`isoWeek`](/api/isoWeek.md), [`ksuid`](/api/ksuid.md), [`length`](/api/length.md), [`ltValue`](/api/ltValue.md), [`mac`](/api/mac.md), [`mac48`](/api/mac48.md), [`mac64`](/api/mac64.md), [`mapItems`](/api/mapItems.md), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxEntries`](/api/maxEntries.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxSize`](/api/maxSize.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`mimeType`](/api/mimeType.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minEntries`](/api/minEntries.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minSize`](/api/minSize.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.md), [`multipleOf`](/api/multipleOf.md), [`nanoid`](/api/nanoid.md), [`nonEmpty`](/api/nonEmpty.md), [`notBytes`](/api/notBytes.md), [`notCodePoints`](/api/notCodePoints.md), [`notEntries`](/api/notEntries.md), [`notGraphemes`](/api/notGraphemes.md), [`notLength`](/api/notLength.md), [`notSize`](/api/notSize.md), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`reduceItems`](/api/reduceItems.md), [`regex`](/api/regex.md), [`returns`](/api/returns.md), [`rfcEmail`](/api/rfcEmail.md), [`safeInteger`](/api/safeInteger.md), [`size`](/api/size.md), [`slug`](/api/slug.md), [`someItem`](/api/someItem.md), [`sortItems`](/api/sortItems.md), [`startsWith`](/api/startsWith.md), [`stringifyJson`](/api/stringifyJson.md), [`title`](/api/title.md), [`toBigint`](/api/toBigint.md), [`toBoolean`](/api/toBoolean.md), [`toCamelCase`](/api/toCamelCase.md), [`toDate`](/api/toDate.md), [`toKebabCase`](/api/toKebabCase.md), [`toLowerCase`](/api/toLowerCase.md), [`toMaxValue`](/api/toMaxValue.md), [`toMinValue`](/api/toMinValue.md), [`toNumber`](/api/toNumber.md), [`toPascalCase`](/api/toPascalCase.md), [`toSnakeCase`](/api/toSnakeCase.md), [`toString`](/api/toString.md), [`toUpperCase`](/api/toUpperCase.md), [`transform`](/api/transform.md), [`trim`](/api/trim.md), [`trimEnd`](/api/trimEnd.md), [`trimStart`](/api/trimStart.md), [`ulid`](/api/ulid.md), [`url`](/api/url.md), [`uuid`](/api/uuid.md), [`value`](/api/value.md), [`values`](/api/values.md), [`words`](/api/words.md)

### Utils

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