Field Validations

Field validations allow you to control the accepted input of a field. The validations available for their respective types are:

  • Make field required
  • Set field as unique
  • Limit charter count
  • Match a specific pattern
  • Restrict a specific pattern
  • Limit input range

For detailed information on which fields support which validations, see our documentation on fields.

Working with Validations

Creating a Validation

  1. Either add a new field to a model in the schema editor or click "edit field" on an existing field.
  2. Navigate to the second tab called "validations".
  3. Enable one of the following validations.mdx

Removing a Validation

  1. Navigate to the validation tab of your field settings.
  2. Change the validation you'd like to remove by unchecking the boolean next to the type of validation.

Types of Validation

Required Validation
If enabled, a value must be present.

Unique Validation
If enabled, no other entry may have an identical value defined for that field.

Character Limit Validation
Text fields (single, multi and markdown) allow you to additionally limit the character input count between a given range, greater than a lower bound or less than an upper bound.

Character limits allow you to define a custom error message.

Limit Input Range Validation
Integers and Floats allow you restrict the allowed numeric range for the fields (always inclusive) to an input between a given range, greater than a lower bound or less than an upper bound.

Input range limits allow you to define a custom error message.

Restrict Specific Pattern / Match Specific Pattern Validations
Text fields can be restricted by either disallowed text patterns or enforced text patterns. These are defined by standard Regular Expressions (RegExp) and do not need to be wrapped in opening or closing slashes. You can modify these pattern searches with additional flags such as ignoring case, enabling multi-line search, single-line search or both.

Pattern restriction limits allow you to define a custom error message.

Explaining what RegExp is and how it works is beyond the scope of this documentation guide, but you can read more about text pattern matching at the Mozilla Developer Documentation site.

Common Regex Patterns

Some common RegExp patterns are:

URLs

(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)

Phone

^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(?:#|ext\.?|extension|x)[\-\.\ \\\/]?(\d+))?$

Email

^([a-z0-9_\.\+-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$

Slug

^[a-z0-9]+(?:-[a-z0-9]+)*$

Let's say you wanted to restrict the use of a certain list of words. A RegExp pattern for this could be .?(bad|naughty|offensive).? which would match, and thus restrict, all the following usages:

  1. Bad
  2. Multi-line
    use of bad
  3. sneakyUseOfBad

Were you expecting something more?

We are constantly contributing to our documentation, but if you spot something we're missing, let us know and we'll be sure to add it.

This site uses cookies to provide you with a better user experience. For more information, refer to our Privacy Policy