Validate

ReferenceSchema API

.validate()

Your own rule for a value. It runs in the Studio as editors type, in your editor, and in CI.

Use it for

  • Rules the built-in checks do not cover
  • Messages written for the editor who broke the rule

Validate Method

.validate()

schema

Custom validation function

In Val Studio

Example

Example

TypeScript
s.string().validate(str => {
   if (str === "test") {
     return "Test is not allowed";
   }
   return str;
})