> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wizflow.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Entity Input Validation

> Validate entity input with built-in rules, regex patterns, and custom error messages

Input validation ensures users provide data in the correct format before proceeding. Wizflow offers several validation types that can be applied to most entities.

<Note>
  **When to use validation:** Add validation rules when you need to enforce specific formats (like phone numbers or ID codes) or business rules (like age ranges or character limits).
</Note>

***

## Validation Types

Wizflow provides 8 built-in validation types to cover common validation scenarios.

<CardGroup cols={2}>
  <Card title="Regex Pattern" icon="code">
    **Use case:** Custom format validation (phone numbers, postal codes, IDs)\
    **Commonly used with:** Text, Text Area, Number
  </Card>

  <Card title="Range Validation (InRange)" icon="arrows-left-right">
    **Use case:** Ensure numbers fall within min/max bounds\
    **Commonly used with:** Number, Amount, Age, Year
  </Card>

  <Card title="Length Validation (LengthInRange)" icon="ruler">
    **Use case:** Enforce minimum or maximum character counts\
    **Commonly used with:** Text, Text Area
  </Card>

  <Card title="No Duplicate Value" icon="ban">
    **Use case:** Prevent repeated entries across a flow\
    **Commonly used with:** All input types
  </Card>

  <Card title="CPR Validation" icon="id-card">
    **Use case:** Validate Danish CPR number format\
    **Commonly used with:** Text, Formatted Number
  </Card>

  <Card title="CPR Modulus 11" icon="calculator">
    **Use case:** Strict CPR validation with modulus 11 checksum\
    **Commonly used with:** Text, Formatted Number
  </Card>

  <Card title="Choices Validation" icon="list-check">
    **Use case:** Ensure valid selection in choice entities\
    **Commonly used with:** Choice, Multi-choice
  </Card>

  <Card title="Reject Choice" icon="circle-xmark">
    **Use case:** Block specific choices with custom actions\
    **Commonly used with:** Choice, Multi-choice
  </Card>
</CardGroup>

***

## Regex Validation

Regex (Regular Expression) validation lets you define custom patterns that user input must match. This is the most flexible validation type for enforcing specific formats.

### Configuration

| Property  | Description                                                       |
| --------- | ----------------------------------------------------------------- |
| `regex`   | The regular expression pattern to match against                   |
| `message` | Error message shown when validation fails (supports translations) |

### Common Regex Examples

Copy and paste these patterns directly into your entity validation settings.

<Tabs>
  <Tab title="Phone Numbers">
    **Danish Phone Number (8 digits)**

    ```
    ^\d{8}$
    ```

    Error message: `Please enter a valid 8-digit phone number`

    **Danish Phone with Country Code**

    ```
    ^(\+45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$
    ```

    Error message: `Please enter a valid Danish phone number (e.g., +45 12 34 56 78)`

    **International Phone (E.164 format)**

    ```
    ^\+[1-9]\d{6,14}$
    ```

    Error message: `Please enter a valid international phone number starting with +`
  </Tab>

  <Tab title="Postal Codes">
    **Danish Postal Code (4 digits)**

    ```
    ^\d{4}$
    ```

    Error message: `Please enter a valid 4-digit postal code`

    **Swedish Postal Code (5 digits, optional space)**

    ```
    ^\d{3}\s?\d{2}$
    ```

    Error message: `Please enter a valid Swedish postal code (e.g., 123 45)`

    **US ZIP Code (5 or 9 digits)**

    ```
    ^\d{5}(-\d{4})?$
    ```

    Error message: `Please enter a valid ZIP code (e.g., 12345 or 12345-6789)`
  </Tab>

  <Tab title="Identification">
    **Danish License Plate**

    ```
    ^[A-Z]{2}\s?\d{5}$
    ```

    Error message: `Please enter a valid license plate (e.g., AB 12345)`

    **IBAN (Generic)**

    ```
    ^[A-Z]{2}\d{2}[A-Z0-9]{4,30}$
    ```

    Error message: `Please enter a valid IBAN number`

    **Danish IBAN**

    ```
    ^DK\d{16}$
    ```

    Error message: `Please enter a valid Danish IBAN (DK + 16 digits)`

    **CVR Number (8 digits)**

    ```
    ^\d{8}$
    ```

    Error message: `Please enter a valid 8-digit CVR number`
  </Tab>

  <Tab title="Text Formats">
    **Letters Only - European (No Numbers)**

    ```
    ^[a-zA-ZÀ-ÖØ-öø-ÿĀ-žḀ-ỿ\s]+$
    ```

    Error message: `Please enter letters only (no numbers or special characters)`

    Supports: German (ä, ö, ü, ß), French (é, è, ê, ç), Spanish (ñ), Nordic (æ, ø, å), Polish (ł, ń, ś), Czech (č, ř, š), and more.

    **Alphanumeric Only**

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

    Error message: `Please enter letters and numbers only`

    **No Special Characters - European**

    ```
    ^[a-zA-Z0-9À-ÖØ-öø-ÿĀ-žḀ-ỿ\s\-]+$
    ```

    Error message: `Please avoid special characters`

    **URL Format**

    ```
    ^https?:\/\/(www\.)?[\w\-]+(\.[\w\-]+)+[\/\w\-\.]*\/?$
    ```

    Error message: `Please enter a valid URL (e.g., https://example.com)`
  </Tab>

  <Tab title="Financial">
    **Account Number (10 digits)**

    ```
    ^\d{10}$
    ```

    Error message: `Please enter a valid 10-digit account number`

    **Danish Bank Account (Reg + Account)**

    ```
    ^\d{4}\s?\d{10}$
    ```

    Error message: `Please enter registration number (4 digits) and account number (10 digits)`

    **Credit Card (16 digits, spaces allowed)**

    ```
    ^(\d{4}\s?){4}$
    ```

    Error message: `Please enter a valid 16-digit card number`
  </Tab>
</Tabs>

***

## Range Validation

Ensure numeric values fall within acceptable bounds.

### Configuration

| Property | Description           |
| -------- | --------------------- |
| `min`    | Minimum allowed value |
| `max`    | Maximum allowed value |

### Examples

<AccordionGroup>
  <Accordion title="Age Restrictions">
    **Adult Only (18+)**

    * Min: `18`
    * Max: `120`

    **Working Age**

    * Min: `18`
    * Max: `67`

    **Senior Discount Eligibility**

    * Min: `65`
    * Max: `120`
  </Accordion>

  <Accordion title="Financial Limits">
    **Loan Amount**

    * Min: `10000`
    * Max: `5000000`

    **Monthly Premium**

    * Min: `100`
    * Max: `50000`

    **Percentage (0-100)**

    * Min: `0`
    * Max: `100`
  </Accordion>
</AccordionGroup>

***

## Length Validation

Control the minimum and maximum number of characters in text inputs.

### Configuration

| Property    | Description                           |
| ----------- | ------------------------------------- |
| `minLength` | Minimum number of characters required |
| `maxLength` | Maximum number of characters allowed  |

### Examples

| Use Case          | Min Length | Max Length |
| ----------------- | ---------- | ---------- |
| Name field        | 2          | 100        |
| Short description | 10         | 200        |
| Comment/feedback  | 20         | 1000       |
| Reference code    | 6          | 6          |
| Password          | 8          | 128        |

***

## No Duplicate Value

Prevent users from entering values that have already been submitted in the same flow session.

### Configuration

| Property | Description                                     |
| -------- | ----------------------------------------------- |
| `key`    | Unique identifier for the duplicate check group |

### Use Cases

* Prevent duplicate email entries in multi-person forms
* Ensure unique reference numbers
* Avoid repeated selections in list-based inputs

***

## CPR Validation

Validates that input matches the Danish CPR (Central Person Register) number format. This is a format-only validation that checks the structure of the CPR number.

### Configuration

No additional configuration required. Simply add the `CPR` validation type to your entity.

### What It Validates

* 10-digit format (DDMMYY-XXXX)
* Valid date portion (day, month, year)
* Correct structure with or without hyphen

### Use Cases

* Customer onboarding flows
* Insurance applications
* Banking KYC processes
* Any flow requiring Danish personal identification

<Warning>
  This validation checks format only. For stricter validation including the mathematical checksum, use **CPR Modulus 11** instead.
</Warning>

***

## CPR Modulus 11

A stricter CPR validation that includes the modulus 11 checksum verification. This ensures the CPR number is not only correctly formatted but also mathematically valid.

### Configuration

No additional configuration required. Simply add the `CPRModulus11` validation type to your entity.

### How It Works

The modulus 11 algorithm multiplies each digit by a weight factor and checks if the sum is divisible by 11. This catches typos and invalid numbers that might pass basic format validation.

### When to Use

| Scenario                                 | Recommended Validation |
| ---------------------------------------- | ---------------------- |
| Quick format check                       | CPR                    |
| High-security flows (banking, insurance) | CPR Modulus 11         |
| Government integrations                  | CPR Modulus 11         |
| Customer self-service                    | CPR                    |

<Note>
  Some valid CPR numbers issued after 2007 may not pass modulus 11 validation due to changes in the Danish CPR system. Consider your use case when choosing between CPR and CPR Modulus 11.
</Note>

***

## Choices Validation

Ensures that a valid selection has been made in choice-based entities. This validation is typically applied automatically to required choice fields.

### Configuration

No additional configuration required. The validation ensures at least one valid option is selected.

### Use Cases

* Required single-choice questions
* Multi-choice with minimum selection requirements
* Dropdown menus that must have a selection

***

## Reject Choice

Block specific choices from being accepted, optionally with custom error messages, warnings, or automated actions like redirects or tooltips.

### Configuration

| Property          | Description                                                         |
| ----------------- | ------------------------------------------------------------------- |
| `choiceKey`       | The key of the choice to reject                                     |
| `choiceCount`     | (Optional) Comparison operator and value for multi-choice scenarios |
| `message.error`   | (Optional) Error message to display (supports translations)         |
| `message.warning` | (Optional) Warning message to display (supports translations)       |
| `action`          | (Optional) Automated action to trigger                              |

### Available Actions

<AccordionGroup>
  <Accordion title="Reroute">
    Redirect the user to a different URL when they select the rejected choice.

    | Property | Description                                                                                                           |
    | -------- | --------------------------------------------------------------------------------------------------------------------- |
    | `url`    | Redirect URL (external: `https://site.com` or internal: `/page`). Use `{{LOCALE}}` placeholder for locale-aware URLs. |
  </Accordion>

  <Accordion title="Video Modal Message">
    Display a modal with a video and title when the rejected choice is selected.

    | Property    | Description                         |
    | ----------- | ----------------------------------- |
    | `titleText` | Modal title (supports translations) |
    | `url`       | Video URL to display                |
  </Accordion>

  <Accordion title="Tooltips">
    Show contextual tooltips to guide the user after selecting the rejected choice.

    | Property      | Description                                                    |
    | ------------- | -------------------------------------------------------------- |
    | `containerID` | ID of the container element                                    |
    | `timeoutInMs` | How long tooltips remain visible                               |
    | `tooltips`    | Array of tooltip configurations with `referenceID` and `label` |
  </Accordion>
</AccordionGroup>

### Examples

**Block Ineligible Users**

```
choiceKey: "under_18"
message.error: "You must be 18 or older to proceed"
```

**Redirect to Alternative Flow**

```
choiceKey: "business_account"
action.type: "reroute"
action.url: "/business-onboarding"
```

**Show Educational Video**

```
choiceKey: "unsure"
action.type: "video-modal-message"
action.titleText: "Understanding Your Options"
action.url: "https://example.com/explainer-video.mp4"
```

***

## Combining Validations

You can apply multiple validation rules to a single entity. Validations are checked in order, and the first failing rule displays its error message.

**Example: Secure Reference Code**

1. **Length Validation:** Min 8, Max 12
2. **Regex:** `^[A-Z0-9]+$` - Uppercase letters and numbers only
3. **No Duplicate Value:** Key `reference_codes`

***

## Best Practices

<CardGroup cols={2}>
  <Card title="Clear Error Messages" icon="message-exclamation">
    Write specific, helpful messages that tell users exactly what's expected. Avoid generic errors like "Invalid input."
  </Card>

  <Card title="Test Your Patterns" icon="vial">
    Always test regex patterns with valid and invalid examples before publishing. Use online tools like regex101.com.
  </Card>

  <Card title="Consider Mobile Users" icon="mobile">
    Some patterns work better with specific keyboard types. Consider using `inputmode` attributes for phone numbers and numeric codes.
  </Card>

  <Card title="Localize Messages" icon="language">
    Error messages support translations. Provide translated versions for all languages your flow supports.
  </Card>
</CardGroup>

***

## Regex Quick Reference

| Pattern  | Meaning                                |
| -------- | -------------------------------------- |
| `^`      | Start of string                        |
| `$`      | End of string                          |
| `\d`     | Any digit (0-9)                        |
| `\D`     | Any non-digit                          |
| `\w`     | Word character (a-z, A-Z, 0-9, \_)     |
| `\s`     | Whitespace (space, tab, newline)       |
| `.`      | Any character except newline           |
| `+`      | One or more of the previous            |
| `*`      | Zero or more of the previous           |
| `?`      | Zero or one of the previous (optional) |
| `{n}`    | Exactly n occurrences                  |
| `{n,m}`  | Between n and m occurrences            |
| `[abc]`  | Any character in the brackets          |
| `[^abc]` | Any character NOT in the brackets      |

***

## Related Pages

* [Collecting Information](/features/collecting-information)
* [Choices & Decisions](/features/choices-decisions)
* [Flow Builder Advanced](/features/flow-builder-advanced)
* [Variables](/features/variables)
