# string

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

Creates a string schema.

```ts
const Schema = v.string<TMessage>(message);
```

## Generics

- `TMessage` `extends ErrorMessage<StringIssue> | undefined`

## Parameters

- `message` `TMessage`

### Explanation

With `string` you can validate the data type of the input. If the input is not a string, you can use `message` to customize the error message.

## Returns

- `Schema` `StringSchema<TMessage>`

## Examples

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

### Email schema

Schema to validate an email.

```ts
const EmailSchema = v.pipe(
  v.string(),
  v.nonEmpty('Please enter your email.'),
  v.email('The email is badly formatted.'),
  v.maxLength(30, 'Your email is too long.')
);
```

### Password schema

Schema to validate a password.

```ts
const PasswordSchema = v.pipe(
  v.string(),
  v.minLength(8, 'Your password is too short.'),
  v.maxLength(30, 'Your password is too long.'),
  v.regex(/[a-z]/, 'Your password must contain a lowercase letter.'),
  v.regex(/[A-Z]/, 'Your password must contain a uppercase letter.'),
  v.regex(/[0-9]/, 'Your password must contain a number.')
);
```

### URL schema

Schema to validate a URL.

```ts
const UrlSchema = v.pipe(
  v.string('A URL must be string.'),
  v.url('The URL is badly formatted.')
);
```

## Related

The following APIs can be combined with `string`.

### 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

[`base64`](/api/base64.md), [`bic`](/api/bic.md), [`brand`](/api/brand.md), [`bytes`](/api/bytes.md), [`codePoints`](/api/codePoints.md), [`creditCard`](/api/creditCard.md), [`cuid2`](/api/cuid2.md), [`check`](/api/check.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), [`excludes`](/api/excludes.md), [`flavor`](/api/flavor.md), [`graphemes`](/api/graphemes.md), [`gtValue`](/api/gtValue.md), [`guard`](/api/guard.md), [`hash`](/api/hash.md), [`hexadecimal`](/api/hexadecimal.md), [`hexColor`](/api/hexColor.md), [`imei`](/api/imei.md), [`includes`](/api/includes.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), [`maxBytes`](/api/maxBytes.md), [`maxCodePoints`](/api/maxCodePoints.md), [`maxGraphemes`](/api/maxGraphemes.md), [`maxLength`](/api/maxLength.md), [`maxValue`](/api/maxValue.md), [`maxWords`](/api/maxWords.md), [`metadata`](/api/metadata.md), [`minBytes`](/api/minBytes.md), [`minCodePoints`](/api/minCodePoints.md), [`minGraphemes`](/api/minGraphemes.md), [`minLength`](/api/minLength.md), [`minValue`](/api/minValue.md), [`minWords`](/api/minWords.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), [`notValue`](/api/notValue.md), [`notValues`](/api/notValues.md), [`notWords`](/api/notWords.md), [`octal`](/api/octal.md), [`parseJson`](/api/parseJson.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`regex`](/api/regex.md), [`rfcEmail`](/api/rfcEmail.md), [`slug`](/api/slug.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), [`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)
