Skip to content

Validation ​

Validation ensures users enter correct data before form submission. Espanso Dynamic Forms uses JSON Schema validation powered by AJV.

How Validation Works ​

Define validation rules in your schema. The form automatically:

  1. Validates input as users type
  2. Shows error messages for invalid fields
  3. Prevents submission until all fields are valid

Required Fields ​

Mark fields that must be filled:

yml
schema:
  type: object
  properties:
    name:
      type: string
    email:
      type: string
  required:
    - name
    - email

Required Array

The required array is at the same level as properties, not inside individual field definitions.

String Validation ​

Minimum and Maximum Length ​

yml
username:
  type: string
  minLength: 3
  maxLength: 20

Pattern (Regular Expression) ​

yml
email:
  type: string
  pattern: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"

Format ​

Some common formats are built-in:

yml
email:
  type: string
  format: email

website:
  type: string
  format: uri

birthdate:
  type: string
  format: date
FormatValidates
emailEmail address
uriURL
dateDate (YYYY-MM-DD)
timeTime (HH:MM:SS)
date-timeISO 8601 datetime

Number Validation ​

Minimum and Maximum ​

yml
age:
  type: integer
  minimum: 0
  maximum: 120

Exclusive Bounds ​

yml
rating:
  type: number
  exclusiveMinimum: 0    # Must be > 0, not >= 0
  exclusiveMaximum: 10   # Must be < 10, not <= 10

Multiple Of ​

yml
quantity:
  type: integer
  multipleOf: 5   # Must be 5, 10, 15, etc.

Array Validation ​

Minimum and Maximum Items ​

yml
tags:
  type: array
  items:
    type: string
  minItems: 1
  maxItems: 10

Unique Items ​

Prevent duplicate selections:

yml
selections:
  type: array
  items:
    type: string
    enum:
      - Option A
      - Option B
      - Option C
  uniqueItems: true

Enum Validation ​

Restrict to specific values:

yml
priority:
  type: string
  enum:
    - High
    - Medium
    - Low

Complete Validation Example ​

yml
schema:
  type: object
  properties:
    username:
      type: string
      minLength: 3
      maxLength: 20
    email:
      type: string
      format: email
    password:
      type: string
      minLength: 8
    age:
      type: integer
      minimum: 13
      maximum: 120
    website:
      type: string
      format: uri
    interests:
      type: array
      items:
        type: string
        enum:
          - Technology
          - Sports
          - Music
          - Art
          - Science
      minItems: 1
      maxItems: 3
      uniqueItems: true
    agreedToTerms:
      type: boolean
      const: true   # Must be true to submit
  required:
    - username
    - email
    - password
    - agreedToTerms

Validation Keywords Reference ​

String Keywords ​

KeywordDescriptionExample
minLengthMinimum character countminLength: 3
maxLengthMaximum character countmaxLength: 100
patternRegex patternpattern: "^[A-Z]"
formatBuilt-in formatformat: email

Number Keywords ​

KeywordDescriptionExample
minimumMinimum value (inclusive)minimum: 0
maximumMaximum value (inclusive)maximum: 100
exclusiveMinimumMinimum value (exclusive)exclusiveMinimum: 0
exclusiveMaximumMaximum value (exclusive)exclusiveMaximum: 100
multipleOfMust be divisible bymultipleOf: 5

Array Keywords ​

KeywordDescriptionExample
minItemsMinimum array lengthminItems: 1
maxItemsMaximum array lengthmaxItems: 10
uniqueItemsNo duplicates alloweduniqueItems: true

General Keywords ​

KeywordDescriptionExample
enumAllowed valuesenum: [A, B, C]
constMust equal this valueconst: true
defaultDefault valuedefault: "Hello"

Validation Behavior ​

Real-Time Validation ​

Fields are validated as users type. Error messages appear below invalid fields.

Submit Validation ​

The form cannot be submitted while validation errors exist.

Optional Fields ​

Fields not in the required array are optional. They're only validated if the user enters a value.