pattern

On this page

Description:

This key defines a regular expression that the Input value must match.

When configured, CloudCannon will require you to enter a value that matches the REGEX pattern.

If the Input already contains an invalid value, CloudCannon will require you to enter a valid string to save your changes, or discard your unsaved changes.

Value must be a valid REGEX string.

If your REGEX string includes a \ character and CloudCannon Configuration File is a .yml file, use single quotes ' around the string to avoid a build error.

This key has no default.

This key is available for Code, Color, File, Select, Text, Rich Text, and URL Inputs.

To use this key in a Select Input, allow_create must be set to true.

Appears in:
├── Text Input
│   └── options
│       └── pattern
├── _inputs
│   └── *
│       ├── Textarea Input
│       │   └── options
│       │       └── pattern
│       ├── Code Input
│       │   └── options
│       │       └── pattern
│       ├── Color Input
│       │   └── options
│       │       └── pattern
│       ├── Rich Text Input
│       │   └── options
│       │       └── pattern
│       ├── File Input
│       │   └── options
│       │       └── pattern
│       └── Choice Input
│           └── options
│               └── pattern
├── URL Input
│   └── options
│       └── pattern
└── Select Input
    └── options
        └── pattern
Type:
string
Examples:

In this example, we want our team to add an email address to the contact_email Input using the correct email format.

Copied to clipboard
_inputs:
  contact_email:
    type: email
    options:
      pattern: '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
      pattern_message: Please use the format ___@___.__
{
  "_inputs": {
    "contact_email": {
      "type": "email",
      "options": {
        "pattern": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
        "pattern_message": "Please use the format ___@___.__"
      }
    }
  }
}
Open in a new tab