---
title: "[Set Up Your Project] - Validation (Regex)"
description: Validation (Regex) property for defining custom validation regular expressions for fields, with guidance on preventing catastrophic backtracking.
url: https://www.contentstack.com/docs/developers/create-content-types/validation-regex
product: Contentstack
doc_type: guide
audience:
  - developers
version: current
last_updated: 2026-03-25
---

# [Set Up Your Project] - Validation (Regex)

This page explains how to use the Validation (Regex) field property to define custom regular-expression validation for field values, and highlights performance and security considerations (catastrophic backtracking). It is intended for developers configuring content types and should be used when you need to validate user input formats such as email, URL, or date.

## Validation (Regex)

The **Validation (Regex) **property helps you define a set of validation options for a given [field](/docs/developers/create-content-types/about-fields).

In general, this field property is used to perform validation checks (format, length, etc.) on the value that the user enters in a field. If the user enters a value that does not pass these checks, it will throw an error.

You can define validation rules by specifying custom validation regular expressions in this property.

Let’s consider a few examples:
- **Email**: If you want to check whether the user has entered a valid email address in the email field, you can specify the following regex code in the Validation (Regex) property:

```
^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+\.[a-zA-z]{2,3}$
```

- **URL**: To check whether a URL entered by a user is valid, you can use the following regex code in the Validation (Regex) property:

```
^(http:\/\/|https:\/\/)?www\.[a-zA-Z0-9:?&=._/-]+\.[a-zA-z]{2,3}$
```

- **Date**: To check whether the date entered by a user is in a valid format, you can define the following regex code. The following code will check whether the entered value is in one of the "dd/mm/yyyy," "dd-mm-yyyy," or "dd.mm.yyyy" formats. It will also validate leap years.

```
^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$
```

**Note: **The **Validation (Regex)** property is available only for [Single Line](/docs/developers/create-content-types/single-line-textbox) and [Multi-Line](/docs/developers/create-content-types/multi-line-textbox) text box fields.

## Prevent Catastrophic Backtracking

When a regular expression either contains a complex validation logic or receives a lengthy input string, executing the validation check becomes time-consuming. The browser has to make millions of backtracking trips through the input string to meet the defined regex validation checks. Regular expressions like these either end up freezing the browser or utilizing 100% of the CPU core process. This issue is known as "catastrophic backtracking."

You can solve this problem in two ways:
- Rewrite the regular expression to lower the possible combinations attempted while backtracking
- Use lookahead to prevent backtracking

Learn more about catastrophic backtracking [here](https://www.regular-expressions.info/catastrophic.html).

**Additional Resource:** Catastrophic backtracking can cause a **regular expression denial of service (ReDOS)** attack. [Read more](https://www.regular-expressions.info/redos.html).

To search for invalid regexes within your stack, please refer to our [Regex Validation CLI Plugin](https://assets.contentstack.io/v3/assets/blt2d43f51baca745a8/bltbae3e9885165e3b2/Regex_Validation_CLI_Plugin_Doc) guide.

Learn more about regular expressions [in the official documentation](http://www.regular-expressions.info/).

## Common questions

### Who can use the Validation (Regex) property?
The **Validation (Regex)** property is available only for [Single Line](/docs/developers/create-content-types/single-line-textbox) and [Multi-Line](/docs/developers/create-content-types/multi-line-textbox) text box fields.

### What happens if a user enters a value that does not match the regex?
If the user enters a value that does not pass these checks, it will throw an error.

### Why should I care about catastrophic backtracking?
Regular expressions like these either end up freezing the browser or utilizing 100% of the CPU core process. This issue is known as "catastrophic backtracking."

### How can I search for invalid regexes within my stack?
To search for invalid regexes within your stack, please refer to our [Regex Validation CLI Plugin](https://assets.contentstack.io/v3/assets/blt2d43f51baca745a8/bltbae3e9885165e3b2/Regex_Validation_CLI_Plugin_Doc) guide.