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

# Field Validators

> Field validators allow you to enforce stricter rules about the data a user can import.

Indepedent of field types, Dromo provides a number of validators that you can use to ensure that get clean data in exactly the format you want them. You can use validators to highlight errors for the user and ensure that they fix the errors before submitting an import.

<img src="https://mintcdn.com/dromo-88ab5238/JhcPQeQwUXntQUrW/images/assets/images/validator_error.png?fit=max&auto=format&n=JhcPQeQwUXntQUrW&q=85&s=8c843391dd40bcabdd144f5e222b4ebd" alt="A validator error message shown to the user" width="612" height="208" data-path="images/assets/images/validator_error.png" />

You can add validation to a field using the `validators` parameter—an array of objects, each with a `validate` rule. Optionally, include an `errorMessage` to show users a custom tooltip when validation fails.

## Validators

### Required

<div class="ml-8">
  <ResponseField name="validate" type="&#x22;required&#x22;" required>
    Specifies that the field cannot be empty.
  </ResponseField>

  <ResponseField name="errorMessage" type="string">
    Custom error message to display when validation fails.
  </ResponseField>
</div>

### Unique

<div class="ml-8">
  <ResponseField name="validate" type="&#x22;unique&#x22; | &#x22;unique_case_insensitive&#x22;" required>
    Specifies that all non-empty values in the column must be distinct (non-equal).

    You can also validate uniqueness case-insensitively with `{ validate: "unique_case_insensitive" }`.
  </ResponseField>

  <ResponseField name="errorMessage" type="string">
    Custom error message to display when validation fails.
  </ResponseField>
</div>

### Unique Across Multiple Fields

<div class="ml-8">
  <ResponseField name="validate" type="&#x22;unique_with&#x22;" required>
    The `unique_with` validator can be used to validate uniqueness across multiple fields.
  </ResponseField>

  <ResponseField name="uniqueKey" type="string" required>
    A unique identifier shared across all fields that should be validated together for uniqueness.
  </ResponseField>

  <ResponseField name="errorMessage" type="string">
    Custom error message to display when validation fails.
  </ResponseField>

  The `unique_with` validator can be used to validate uniqueness across multiple fields.

  To use it, place a `unique_with` validator on each field that you want to be part of the uniqueness validation, all sharing the same `uniqueKey`.

  Here is an example set of fields using `unique_with` validators used to validate that the combination of the first name and last name fields are unique.

  <CodeGroup>
    ```javascript theme={null}
    [
    {
        label: "First Name",
        key: "firstName",
        validators: [
        {
            validate: "unique_with",
            uniqueKey: "full name",
        },
        ],
    },
    {
        label: "Last Name",
        key: "lastName",
        validators: [
        {
            validate: "unique_with",
            uniqueKey: "full name",
        },
        ],
    },
    ]
    ```
  </CodeGroup>

  And here is an example of the validators in action:

  <img src="https://mintcdn.com/dromo-88ab5238/JhcPQeQwUXntQUrW/images/assets/images/unique_with_example.png?fit=max&auto=format&n=JhcPQeQwUXntQUrW&q=85&s=617da105cc8d08f05d7e0bd3cef77e07" alt="unique with example" width="1904" height="624" data-path="images/assets/images/unique_with_example.png" />
</div>

### Match a Regular Expression

<div class="ml-8">
  <ResponseField name="validate" type="&#x22;regex_match&#x22; | &#x22;regex_exclude&#x22;" required>
    You can validate that a field matches the given regular expression with the `regex_match` validator.

    Conversely, you can validate that a field does *not* match a regular expression with the `regex_exclude` validator.
  </ResponseField>

  <ResponseField name="regex" type="string | RegExp" required>
    The regular expression pattern to match against.
  </ResponseField>

  <ResponseField name="regexOptions" type="RegexOptions">
    Optional regex configuration options.
  </ResponseField>

  <ResponseField name="errorMessage" type="string">
    Custom error message to display when validation fails.
  </ResponseField>

  The Dromo uploader uses standard JavaScript regular expressions. You can set the `regex` key as either a `RegExp` literal/object or a string.

  If you choose to use a string, be careful to properly escape special characters in your regex. For example, the regex `/^"\d+"$/` should be passed in as `"^\"\\d+\"$"`. Additionally, if using a string, note that you cannot pass in regex flags directly in your regex. Instead, you may optionally provide a `regexOptions` parameter with the validator which takes an object with the following keys:

  * `ignoreCase: boolean` - Case insensitive flag (regex flag `i`)
  * `dotAll: boolean` - Matches all including any line breaks (regex flag `s`)
  * `multiline: boolean` - Multiline flag (regex flag `m`)
  * `unicode: boolean` - Unicode flag (regex flag `u`)
</div>

### Require with Other Fields

<div class="ml-8">
  <ResponseField name="validate" type="&#x22;require_with&#x22; | &#x22;require_without&#x22; | &#x22;require_with_all&#x22; | &#x22;require_without_all&#x22;" required>
    You can use these validators to require that a field be non-empty *only if* other fields are present or empty. There are four variations.
  </ResponseField>

  <ResponseField name="fields" type="string[]" required>
    Array of field keys to check against.
  </ResponseField>

  <ResponseField name="errorMessage" type="string">
    Custom error message to display when validation fails.
  </ResponseField>

  You can use these validators to require that a field be non-empty *only if* other fields are present or empty. There are four variations:

  > `{ validate: "require_with", fields: [<fieldKey>, ...] }`

  This will require that the field has a value if **any** of the fields listed in the `fields` array are **non-empty**.

  > `{ validate: "require_without", fields: [<fieldKey>, ...] }`

  This will require that the field has a value if **any** of the fields listed in the `fields` array are **empty**.

  > `{ validate: "require_with_all", fields: [<fieldKey>, ...] }`

  This will require that the field has a value if **all** of the fields listed in the `fields` array are **non-empty**.

  > `{ validate: "require_without_all", fields: [<fieldKey>, ...] }`

  This will require that the field has a value if **all** of the fields listed in the `fields` array are **empty**.
</div>

### Require with Other Field Values

<div class="ml-8">
  <ResponseField name="validate" type="&#x22;require_with_values&#x22; | &#x22;require_without_values&#x22; | &#x22;require_with_all_values&#x22; | &#x22;require_without_all_values&#x22;" required>
    You can use these validators to require that a field be non-empty *only if* other fields have specific values. There are four variations.
  </ResponseField>

  <ResponseField name="fieldValues" type="{ [fieldKey: string]: string }" required>
    Object mapping field keys to their required values.
  </ResponseField>

  <ResponseField name="errorMessage" type="string">
    Custom error message to display when validation fails.
  </ResponseField>

  You can use these validators to require that a field be non-empty *only if* other fields have specific values. There are four variations:

  > `{ validate: "require_with_values", fieldValues: { <fieldKey>: <fieldValue>, ... } }`

  This will require that the field has a value if **any** of the fields contain the corresponding value specified under `fieldValues`.

  > `{ validate: "require_without_values", fieldValues: { <fieldKey>: <fieldValue>, ... } }`

  This will require that the field has a value if **any** of the fields **do not** contain the corresponding value specified under `fieldValues`.

  > `{ validate: "require_with_all_values", fieldValues: { <fieldKey>: <fieldValue>, ... } }`

  This will require that the field has a value if **all** of the fields contain the corresponding value specified under `fieldValues`.

  > `{ validate: "require_without_all_values", fieldValues: { <fieldKey>: <fieldValue>, ... } }`

  This will require that the field has a value if **all** of the fields **do not** contain the corresponding value specified under `fieldValues`.
</div>

### Length

<div class="ml-8">
  <ResponseField name="validate" type="&#x22;length&#x22;" required>
    Validates that a field's value falls within a minimum or maximum number of characters.

    Either min, max, or both must be defined. Values are inclusive.

    The length validator cannot be used with non-string-based fields, such as number or date fields.
  </ResponseField>

  <ResponseField name="min" type="number">
    Minimum number of characters allowed.
  </ResponseField>

  <ResponseField name="max" type="number">
    Maximum number of characters allowed.
  </ResponseField>

  <ResponseField name="errorMessage" type="string">
    Custom error message to display when validation fails.
  </ResponseField>
</div>

### Alphabetical

<div class="ml-8">
  <ResponseField name="validate" type="&#x22;alphabetical&#x22;" required>
    Validates that a field's value only contains alphabetical characters (a-z, lowercase and uppercase).
  </ResponseField>

  <ResponseField name="errorMessage" type="string">
    Custom error message to display when validation fails.
  </ResponseField>
</div>
