Validation Rules Overview

Validation rules are help maintain data integrity in your Knack applications by setting specific criteria for data entry.

This article contains the following sections:


 

Validation rules are a powerful functionality that helps maintain data integrity in your Knack applications by setting specific criteria for data entry. These rules ensure that information entered into your database meets your defined standards before being saved or submitted.

What is a Validation Rule?

A validation rule acts as a gatekeeper for your data, ensuring that the information entered meets specific criteria before being accepted. These rules help maintain data consistency and accuracy across your application.

Common use cases include:

  • Restricting file types and sizes
  • Setting numerical ranges
  • Implementing text requirements
  • Validating date ranges

Tip: Validation rules always apply to Live App environments, providing consistent data from Live App users. Data entered in the Builder can choose to override validation rules.

 

Creating and Managing Validation Rules

Adding a New Validation Rule

  • Navigate to the Records or Fields tab in the DataTable
  • Open Validation rules in the right panel
  • Select the field that the rule should apply to.
  • Create criteria:
    • Condition: Select the appropriate operator (equals, contains, greater than, etc.)
    • Value: Define the criteria that must be met
    • Message: Write a message that appears when validation fails
  • Click on the "+ Criteria" button if you'd like to add additional validation rules for this field. S

  • Multiple Validation rules can be added to one or more fields.

Tip: Include fields with validation rules in the Live App elements view in order to be validated against. 

Validation rules do not check for case sensitivity. 

validation1

validation2

validation 3

Once Validation rules are added, they can be edited, duplicated, or deleted. 

validation 4

💡 Best Practices :

Plan your validation rules to ensure they don't conflict with each other or create unnecessary restrictions for users.

Write a clear, helpful message that appears when validation fails.

 

How Validation Rules Work in the Live App

In the Live App, if the data entered does not meet the Validation rule requirements, the user will be prompted to correct their changes before saving edits or submitting forms.

In the examples below, the Live App user attempts to submit a form when the Date field is empty, and the Total Amount is higher than 5.  The custom message is shown, and the form can be submitted once the corrections are made.

validation_5validation_6Validation_7validation_8

Note: Validation rules are not checked when importing data into an existing table in the Builder, or with batch updates. When editing or adding records in the Builder, the user has options to Save records while bypassing Validation rules.

 

Regular Expressions (Regex) and Validation 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 Regex 101. 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.

Caution:  Please note that we are unable to provide support for regular expressions. This means that we cannot assist with setup or troubleshooting related to regular expressions.

Additionally, as regular expressions involve code-based solutions, we cannot guarantee their functionality or full compatibility with Knack.