---
title: String Length Validation
description: Validates that string values meet specified length requirements
group: Validity
---

# String Length Validation

The **String Length Validation** rule ensures string values adhere to defined length constraints.  
This rule is commonly used to:

- Validate fixed-length identifiers like phone numbers or country codes  
- Enforce minimum/maximum length requirements for address fields, codes, etc.  
- Ensure consistent data entry standards  

**Example Usage**:  
- Verify all country codes are exactly 2 characters long (like "IN", "US")  
- Ensure phone numbers are between 10-15 digits after trimming  
- Validate access tokens have a minimum of 32 characters  

## Configuration Fields  

### Rule-Specific Configuration  

| Field Name          | Description                                         | Required | Data Type / Options                |
|:-------------------|:----------------------------------------------------|:----------|:-----------------------------------|
| **Minimum Length**      | Minimum allowed length                                | No       | Integer                            |
| **Maximum Length**      | Maximum allowed length                                | No       | Integer                            |
| **Exact Length**        | Required exact length                                 | No       | Integer                            |
| **Left Trim**           | Trim whitespace from start of string                  | No       | `true` / `false` (default: `true`) |
| **Right Trim**          | Trim whitespace from end of string                    | No       | `true` / `false` (default: `true`) |
| **Consider Whitespace** | Include whitespace characters in length calculation   | No       | `true` / `false` (default: `false`)|

---

### Success Criteria Configuration  

This section defines how the rule’s outcome is measured against expected thresholds.

| Field Name        | Description                                                 | Required   | Options / Format                                                     |
|:------------------|:------------------------------------------------------------|:-----------|:----------------------------------------------------------------------|
| **Operator**        | Comparison operation for the result count                   | Yes        | `GreaterThan`, `LessThan`, `EqualTo`, `Between`                      |
| **Threshold Value** | Value for comparison (single value for most operators)      | Conditional| Number                                                               |
| **Threshold Min**   | Minimum value (for `Between` operator)                      | Conditional| Number                                                               |
| **Threshold Max**   | Maximum value (for `Between` operator)                      | Conditional| Number                                                               |
| **Is Percentage**   | Whether the threshold represents a percentage or count      | No         | `true` / `false` (default: `false`)                                  |
| **Allow Nulls**     | Should null values be treated as valid                      | No         | `true` / `false` (default: `false`)                                  |
| **Check For Match** | When `false`, validates for negation of the condition       | No         | `true` / `false` (default: `true`)                                   |

---

## Sample Input Data  

| UserID | CountryCode | PhoneNumber      |
|:--------|:--------------|:------------------|
| 1      | IN           | 9876543210        |
| 2      | US           | 11234567890       |
| 3      | UK           | 447890123456      |
| 4      | IN           |  98765 43210      |
| 5      | null         | null              |

---

## Sample Configurations  

### Example 1: Country Code Exact Length



| Configuration Field | Value         |
|:---------------------|:---------------|
| Column                | CountryCode     |
| Exact Length          | 2               |
| Operator              | GreaterThan     |
| Threshold Value       | 4               |
| Is Percentage         | false           |
| Allow Nulls           | false           |
| Check For Match       | true            |

**Explanation**:  
Ensures that at least 4 country codes are exactly 2 characters long (e.g., "IN", "US").

---

### Example 2: Phone Number Length Range



| Configuration Field | Value         |
|:---------------------|:---------------|
| Column                | PhoneNumber     |
| Minimum Length        | 10              |
| Maximum Length        | 15              |
| Left Trim             | true            |
| Right Trim            | true            |
| Operator              | GreaterThan     |
| Threshold Value       | 4               |
| Is Percentage         | false           |
| Allow Nulls           | false           |
| Check For Match       | true            |

**Explanation**:  
Validates that at least 4 phone numbers have lengths between 10 and 15 characters (after trimming), ensuring basic phone number formatting.

---

## Sample Output  

| Column Name   | Rule Name               | Success Count | Failure Count | Null Count | Within Threshold |
|:---------------|:--------------------------|:---------------|:---------------|:------------|:------------------|
| CountryCode   | String Length Validation | 4             | 0             | 1          | Yes              |
| PhoneNumber   | String Length Validation | 4             | 0             | 1          | Yes              |

---
