Table of Contents

Validation Rules

Lesley Updated by Lesley

What is a Validation Rule?

Validation rules allow for values which are or are not allowed on a specific field. Validation rules apply when adding or editing a field, both in the Builder and on Live App pages, and appear as a message if the rule has not been met. For example, you can:

  • Limit the number of characters in a paragraph text field
  • Restrict files to specific types and sizes
  • Allow only a specific range of numbers and dates
  • Run your own regular expressions on a Short Text field
  • Set password minimum and maximum character counts on a User Role password field

Manage Validation Rules

Add a Validation Rule

From the "Data" section in the Builder, select the table where the field is located, where you want to add your validation rule. In order to add a validation rule to a field, you'll need to edit that field. To do so, click on the gear icon on the field.

  1. Click on the Validation Rules tab from the Advanced Options modal.
  2. Check the checkbox next to "Add field validation rules" to start adding rules for this field.
  3. Add your When condition: a field on that table, the condition, and the value. Available conditions will depending on the type of the field chosen.
  4. Type the message you want to appear when the condition in the When section is not met.
  5. Click on the "Add Rule" button if you'd like to add additional validation rules for this field. See the section below Multiple Validation Rules for details on more than one validation rule on a field.

The above rule states that When this field's character count is higher than 500, we will display a custom message alerting the user has gone over that character count.

Edit a Validation Rule

From the Data section in the Builder, select the table where the field is located, where you want to edit your validation rule.

Click the check list icon on the field where the validation rule is saved, and then click on the "Validation Rules" tab to edit those rules.

Delete a Validation Rule

From the Data section in the Builder, select the table where the field is located with the validation rules. Click the check list icon on the field where the validation rule is saved, and then click on the "Validation Rules" tab to delete a rule.

Click the delete icon on an individual rules to delete the rule.

Uncheck the checkbox "Add field validation rules" to remove all validation rules from the field you are editing.

Unchecking the "Add field validation rules" or the minus icon on an individual rules is destructive and will cause all rule(s) to be removed, so confirm this is the correct action in your app before proceeding.

Multiple Validation Rules

You can add multiple validation rules to a single field to check for different conditions. If no conditions match (that is, if no rules are broken), the field will submit as usual:

When a validation rule finds a match, your user will be notified and the affected field will be highlighted:

Regular Expressions (Regex) and Validations Rules

  • Regular expressions, or regex, can also be used with validation rules to define the data that users enter. For example, ^[0-9]{8}$ can be used to require 8 numbers and ^[A-Z]{3}$ can be used to require 3 uppercase letters.
  • You can learn about, write, and test regex at https://regex101.com/. Use the ECMAScript/Javascript option.
  • Errors with a regular expression can result in a form that's stuck spinning, however, no error message is displayed. If you see this behavior and you're using regular expressions in your validation rules, please check to make sure there are no errors in the regex using Rubular mentioned above.
Regex falls outside the scope of our support. This means that we’re unable to help further with setup or troubleshooting. Additionally, with a code-based solution, we can’t guarantee its functionality or full compatibility with Knack. 

For resources to help with regex, read more here.

Notes & Troubleshooting

  • Fields that have at least one validation rule applied will show with a check mark icon adjacent to the field name on the Builder fields page.
  • Validation Rules only work for form submissions and inline edits.
  • Fields that are included in validation rules must be on the view to be validated against.
  • Imports, form rules, and batch updates do not perform validation checks.
  • Validation rules do not check for case-sensitivity. 

How did we do?

Field Types

Date Equation Settings

Contact