LogoLogo
Back to studio
  • 🧠Core Concepts
    • Introduction to Formsort
    • Formsort quickstart guides
      • Add content and collect answers
      • Capture demographic data
      • Add informational content
      • Template your variables
      • Add conditional logic
      • Using conditional logic with Calculated and API variables
      • Add a scheduling option
      • End the flow
      • Review your variable schema
      • Set up integrations
    • How data works in Formsort
      • Responder UUIDs
    • Understanding flows
    • Versioning in Formsort (Deploying)
      • Variant revisions
      • Managing revisions
  • ✨Creating Flows
    • Building a new flow
      • Groups
      • Steps
      • Copy-pasting form content
  • Adding questions and content
    • Questions
      • Select
      • Text
      • Address
      • Comparison
      • Confirmation
      • Date
      • Date & time
      • Email address
      • File upload
      • Grid choice
      • Iframe
      • Image upload
      • Number
      • Payment
      • Phone number
      • Postal code
      • Question group
      • Region
      • Signature
      • SSN
      • Yes/No
    • Content
      • Statement
      • Image
      • Next button
      • Video
      • Divider
      • Map
  • Controlling the flow with conditions and logic
    • Advanced logic
  • Variable templating
  • Redirects and endings
  • Field validation
  • Flow and variant management
  • Content library
  • 🧬JSON Form Definition
  • JSON schemas
  • Validating flow schemas
  • Events subscriptions
  • Flow content data format
  • 🎨Styling
    • Customizing appearance
      • Content area & form layout
      • Buttons
      • Typography
      • UI states
      • Color and dimension variables
      • Question containers
      • Inputs and dropdowns
      • Checkmarks
      • Tables
      • Sliders
      • Divider lines
      • Progress bar
      • Comparison cards
      • Animations and transitions
  • CSS & Advanced Styling
    • Custom CSS overrides
    • Step styling
    • CSS reference
  • 🔁Form Behavior Settings
    • Variant settings
      • Form behavior for returning users
      • Group ranking API
    • Navigation sidebar
  • ⚙️Response Data Collection & Management
    • Schema (variables)
      • Variables from questions
      • Externally provided variables
      • Calculated variables
      • API lookups
      • System Library variables
      • Orphaned variables
  • Saving & retrieving responses
  • Importing Data
    • URL parameters
    • POST body
    • Embed query parameters
  • 📊Analytics and Attribution
    • Built-in analytics
    • Split testing
  • 🚀Publishing and Deployment
    • Live preview overview
    • Environments
      • Loading different environments
    • Embedding
      • Web-embed API
        • React-embed
      • Adding authentication
      • Embedding forms in iOS and Android
      • Setting up a dev environment
    • Pre-deployment checklist
  • 📁Workspace Management
    • Accounts
      • Roles and permissions
    • Custom domains
    • Workspace domain detection
  • 🛠️Formsort Admin API
    • Admin API
  • 🔌Integrations
    • Form answers and events
      • Analytics events
      • Signed requests
      • Event payload shape
      • Submission frequencies
      • Runtime error reporting
    • Integration reference
      • Amplitude
        • Amplitude cross domain tracking
      • BigQuery
      • FullStory
      • Google Analytics
        • Updating from Universal Analytics to GA4
      • Google Cloud Storage
      • Google Sheets
      • Google Tag Manager (GTM)
        • JavaScript triggered by flow events
      • Hubspot
      • Jornaya
      • Optimizely
      • PostgreSQL
      • Redshift
      • Rudderstack
      • S3
      • Salesforce
      • Segment
        • Segment Setup
        • Segment cross domain tracking
      • Stripe
      • TrustedForm
      • Webhooks
        • Zapier
Powered by GitBook
On this page
  • Built-in Validators
  • Custom Validators (Enterprise Only)
  • Defining Custom Validators
  • Regular expression rules
  • Custom code rules
  • Async custom code
  • Testing validators
  • Using custom validators in a flow
  • Updating custom validators
  • Deleting Validators

Was this helpful?

Field validation

PreviousRedirects and endingsNextFlow and variant management

Last updated 10 days ago

Was this helpful?

Field validation ensures that the data collected in your flows meets defined formatting, business, and quality requirements. Formsort supports both built-in and custom validators.


Built-in Validators

Formsort includes many default validators for common input types:

  • Number questions: Enforce min/max value, integer constraints, and step intervals.

  • Email fields: Automatically validate email formatting.

  • Text fields: Can be configured with length or character restrictions.

These default validators cover the most common cases. For advanced use cases, custom validators are available.


Custom Validators (Enterprise Only)

Custom validators allow you to define your own validation logic using regular expressions, custom code, or asynchronous API calls. They are defined at the workspace level and can be reused across flows.

Defining Custom Validators

Custom validators are composed of two main parts:

1. Validator Metadata

Metadata includes:

  • Name and description (used for identification in the Studio)

  • Answer type (e.g., string, number, object) – this controls which questions or variables can use the validator

Ensure the validator's answer type matches the target question’s type—e.g., string validators won't apply to number fields.

2. Validation Rules

Validators can contain multiple rules. Each rule must pass for the value to be considered valid.

Rule Severity

  • Error: Blocking. The responder cannot proceed unless the input is corrected.

  • Warning: Non-blocking. The responder is alerted, but may choose to proceed.

Regular expression rules

Regular expressions (regex) are available only for string inputs. You can create rules for inputs that must match or must not match a given pattern.

Example: Twitter Handle Validator

Rule Type
Pattern
Error Message

Must match

^[a-zA-Z0-9_]+$

A username can only contain alphanumeric characters (A–Z, 0–9) and underscores.

Must match

^.{1,15}$

Handles must be between 1 and 15 characters long.

Must not match

`Twitter

Admin` (case-insensitive)

Rules 1 and 2 (and probably 3) can be collapsed into a single regular expression that checks for both, which would be ^[a-zA-Z0-9_]{1,15}$.

Splitting out rules is preferred, as it allows for more targeted error messages. We can warn users with a specific message when they have an invalid character OR their handle is too long, making it easier to see what's wrong with the input and correct it.

Custom code rules

For more flexibility, you can write custom validation functions using TypeScript.

Example:

function myFunction(value: string): ValidatorResult | undefined { // readonly line
  if (value.match(/admin|twitter/i)) {
    return {
      severity: 'error',
      message: 'Handle cannot contain the words "admin" or "twitter"'
    }
  }
  if (value.match(/[^a-zA-Z0-9_]/)) {
    return {
      severity: 'error',
      message: 'A username can only contain alphanumeric characters (letters A-Z, numbers 0-9) with the exception of underscores.'
    }
  }
  if (value.length > 15) {
    return {
      severity: 'error',
      message: 'Usernames cannot be more than 15 characters long'
    }
  }
}
  • Return a ValidatorResult when the input is invalid.

  • Return undefined when input passes validation.

Note: Only the first validation error is shown—custom functions exit at the first return.

Async custom code

Enable async mode to fetch data from external sources during validation using await.

Example (hypothetical Twitter handle check):

function myFunction(value: string): Promise<ValidatorResult | undefined> { // readonly line
  const res = await fetch('https://api.twitter.com/check-handle');
  const handleInfo = await res.json();
  if (handleInfo.taken) {
    return {
      severity: 'error',
      message: 'This handle has already been registered'
    }
  }
}

You must enable the Async checkbox in the validator configuration.

Testing validators

Use the Test tab to try out inputs and preview validation behavior:

  • Regex rules: All rules are evaluated in parallel. Violations for each rule are shown independently.

  • Custom functions: Only the first failed check is returned.

Examples:


Using custom validators in a flow

Once created, custom validators become selectable in Question settings (if the question’s data type matches the validator).


Updating custom validators

You can modify validators at any time. However:

  • Flows using the validator need to be redeployed to pick up changes.

  • Use the Show usages option to view which flows depend on a validator.

Deleting Validators

Custom validators can be deleted from the validator list.

  • Flows already using the validator will continue to function.

  • Deleted validators will no longer be available to assign to new questions or answers.

Using the Regular Experssion UI (described ) has the added benefit of evaluating all rules concurrently, and outputting an error message for each rule that is violated:

above
Custom validators are defined at the workspace level
Writing a custom code validator
Rule 1 being enforced
Rule 2 being enforced
Rule 3 being enforced
All rules being enforced at once
Picking a validator within the content editor