> ## Documentation Index
> Fetch the complete documentation index at: https://codebeans-cb-checkout-rules.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Regex Matching Rule

> Check fields against a pattern, such as a postcode, phone number or ID format.

A regular expression (regex) is a pattern that describes what a value should look like. Use this rule when a field must follow an exact format, like a 6-digit postcode or a 10-digit mobile number.

## How it works

You add one or more fields. For each field you set a pattern and choose when to block:

* **Matched**: block checkout when the value **matches** the pattern. Use this for things you don't want, such as numbers in a name.
* **Unmatched**: block checkout when the value **doesn't match** the pattern. Use this for a format the value must follow, such as a postcode.

Empty fields are not checked. Matching ignores upper and lower case.

![Matched blocks John2 because it contains a number. Unmatched blocks 11001 because it isn't a 6-digit postcode.](https://mintcdn.com/codebeans-cb-checkout-rules/9lVKcptiAqYAtTXj/images/regex-when.svg?fit=max\&auto=format\&n=9lVKcptiAqYAtTXj\&q=85\&s=b819ee4730fac2e62f4fa0c0ecac54b9)

## Set up the rule

**1. Select the fields**

Under **Add validation to these fields**, click the box and tick the fields to check. Each field gets its own card.

**2. Enter a pattern**

In the field's card, type a pattern in **Custom Regular Expression**, or click the presets button and choose one of the ready-made patterns. Choosing a preset also sets **When** for you.

**3. Choose when to block**

Under **When**, choose **Matched** or **Unmatched**.

**4. Choose shipping or billing**

For address fields, tick **Shipping address**, **Billing address** or both.

**5. Write the message**

Under **Message to display** in the field's card, write what the customer sees. English is required for each field.

### Fields you can check

| Group | Fields |
| - | - |
| Contact | Contact email, Contact phone |
| Shipping / Billing address | City, Address line 1, Address line 2, Company, First name, Last name, Zip, Phone |

## Ready-made patterns

| Preset | Pattern | Blocks when |
| - | - | - |
| Email | `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$` | The value isn't a valid email |
| Contains numbers | `\d+` | The value contains a number |
| Contains special characters | `[^a-zA-Z0-9\s]` | The value contains a symbol |
| Indian mobile number | `^[6-9]\d{9}$` | The value isn't a 10-digit Indian mobile number |
| South African identity card number | `^\d{13}$` | The value isn't 13 digits |

## More example patterns

| Use | Pattern | When |
| - | - | - |
| US ZIP code | `^\d{5}(-\d{4})?$` | Unmatched |
| UK postcode | `^[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}$` | Unmatched |
| India PIN code | `^[1-9][0-9]{5}$` | Unmatched |
| Numbers only | `^[0-9]+$` | Unmatched |
| No numbers in a name | `\d` | Matched |

> [!TIP]
>
> Not sure how to write a pattern? Describe what you need to an AI assistant, or [contact us](https://codebeans-cb-checkout-rules.mintlify.site/help/support.md) with your example and we'll help you write it.

> [!WARNING]
>
> Test every pattern with the **Testing** status first. A pattern that is too strict can block real customers. If a pattern isn't valid, the app skips that field instead of blocking checkout.

## Other settings

This rule also has the **Countries**, **Rule status** and **Checkout behavior** settings described in [Common rule settings](https://codebeans-cb-checkout-rules.mintlify.site/rules/common-settings.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.