Overview

String Schema

s.string()

Use the s.string() schema to represent text. Use .multiline() when the value can hold line breaks, and s.code({ language }) when it holds source code.

Methods:
.validate: method

Custom validation function

.maxLength(n): method

Maximum length validation

.minLength(n): method

Minimum length validation

.regex(pattern): method

Regex pattern validation

s.string().regex(/Example/)
.multiline(): method

Let the string hold line breaks. The field becomes a growing text box instead of a single-line input.

For strings that hold source code or configuration, use s.code() instead - a language is part of what the value is, not how the field is drawn.

s.string().multiline()
s.code({ language: "typescript" })
Examples:
Basic validation
s.string().maxLength(100)
Multi-line text
const schema = s.object({
  description: s.string().multiline(),
});
Code editor
const schema = s.object({
  jsonConfig: s.code({ language: "json" }),
  tsCode: s.code({ language: "typescript" }),
  cssStyles: s.code({ language: "css" }),
});