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

# RegExp

> Check that a value matches a pattern.

The **RegExp** validator checks a value against a regular expression without changing it. Use it for values that have to follow a known shape — reference numbers, postal codes, internal identifiers.

## Options

| Option | What it does |
| - | - |
| **Match pattern** | Required. A JavaScript regular expression the value must match. |
| **Match flags** | JavaScript regular expression flags. Defaults to `gs`. |

The pattern has to *match*, not match the whole value, so anchor it with `^` and `$` when the whole value must conform. `^\d{4}$` accepts only a four-digit value, while `\d{4}` accepts anything containing four digits in a row.

## Examples

| Goal | Match pattern |
| - | - |
| Exactly four digits | `^\d{4}$` |
| An invoice number like `INV-1023` | `^INV-\d+$` |
| A Norwegian postal code | `^\d{4}$` |
| A value containing no letters | `^[^A-Za-z]*$` |

## How it behaves

| Situation | Result |
| - | - |
| The value matches | Passes |
| The value does not match | Flagged — `Text does not match expected pattern`, or your own message |
| The pattern or flags are invalid | Flagged — `RegEx Validator: Invalid pattern or flags specified` |
| The field is empty | Passes — use [Cannot be empty](/core-concepts/ai-model/validators) to require a value |

<Note>
  This is the validator, which checks values and leaves them alone. To rewrite a value with a regular expression, use the [RegExp formatter](/core-concepts/ai-model/regex-formatter) instead.
</Note>
