---
title: "How to Use Regex for Data Validation in the BoldSign API"
description: "Learn how to use regular expression validation for form fields in eSignatures to ensure data integrity and prevent errors during the signing process."
url: "https://boldsign.com/blogs/how-to-use-regex-for-data-validation-in-the-boldsign-api/"
---

1. [Blog](https://boldsign.com/blogs.md)
2. [API](https://boldsign.com/category/api.md)

# How to Use Regex for Data Validation in the BoldSign API

[Starvritsa Buhungi](https://boldsign.com/author/starvritsa-buhungi/) May 22, 2024 Updated March 26, 2026 4 min read

Ensuring data is accurate and formatted correctly is essential in any application or context. BoldSign provides an easy way to validate data when you create a document by integrating text box fields and regex validation. This blog will demonstrate how regex validation is applied to text box files using the BoldSign API.

## Regex validation

Imagine expecting an email address but receiving a jumble of letters instead. [Regex validation](https://developers.boldsign.com/text-tags/advanced-usage/?region=us#validation) ensures that only correctly formatted data, such as email addresses, phone numbers, dates, etc., is entered based on your requirements using special strings and patterns. This ensures clean and accurate user input.

## Integrating regex validation in the BoldSign API

BoldSign simplifies the process of integrating regex validation with your documents through its comprehensive API. By associating the [text box field](https://support.boldsign.com/kb/article/19214/add-validation-to-the-textbox-form-field-via-api) with a signer or role and specifying the regex you want, you can restrict the data to be entered during the signing process. If the validation fails, you can provide a message to the signer explaining why it failed.

Currently, regex validation can only be applied to the text box field in BoldSign.

## Code snippets for adding regex validation

The following code examples demonstrate how to add regex validation that accepts only numbers in the text box field.

```
curl -X 'POST' \
  'https://api.boldsign.com/v1/document/send' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: {API key}' \
  -H 'Content-Type: multipart/form-data' \
  -F 'Message={your message}' \
  -F 'Signers={
  "name": "starvritsa",
  "emailAddress": "starvritsabuhungi@boldsign.dev",
  "privateMessage": "sign",
  "authenticationType": "None",
  "deliveryMode": "Email",
  "signerType": "Signer",
  "formFields": [
    {
      "id": "textbox1",
      "name": "textbox1",
      "fieldType": "Textbox",
      "pageNumber": 1,
      "bounds": {
        "x": 140,
        "y": 140,
        "width": 82,
        "height": 32
      },
      "isRequired": true,
      "validationType": "CustomRegex",
      "validationCustomRegex": "^\\d+$",
      "validationCustomRegexMessage": "Enter numbers only"
    }
  ]
}' \
  -F 'Files=@{Your file path};type=application/pdf' \
  -F 'Title={Document title}'
```

```
var apiClient = new ApiClient("https://api.boldsign.com", "{your API key}");
var documentClient = new DocumentClient(apiClient);

var documentFilePath = new DocumentFilePath
{
   ContentType = "application/pdf",
   FilePath = "{file path}",
};

var filesToUpload = new List
{
    documentFilePath,
};

var signatureField = new FormField(
   id: "sign",
   isRequired: true,
   type: Type.Signature,
   pageNumber: 1,
   bounds: new Rectangle(x: 100, y: 100, width: 100, height: 50)),
    validationType: "CustomRegex",
    validationCustomRegex: "^\\d+$",
    validationCustomRegexMessage: "Enter numbers only");

var formFieldCollections = new List()
{
    signatureField
};

var signer = new DocumentSigner(
  signerName: "David",
  signerType: SignerType.Signer,
  signerEmail: "starvritsabuhungi@boldsign.dev",
  formFields: formFieldCollections,
  locale: Locales.EN);

var documentSigners = new List()
{
    signer
};

var sendForSign = new SendForSign()
{
   Message = "please sign this",
   Title = "Agreement",
   Signers = documentSigners,
   Files = filesToUpload,

};
var documentCreated = documentClient.SendDocument(sendForSign);
```

```
import requests
import json

url = "https://api.boldsign.com/v1/document/send"

signer_data = {
    "name": "hanky",
    "emailAddress": "starvritsabuhungi@boldsign.dev.com",
    "signerType": "Signer",
    "signerRole": "Signer",
    "formFields": [
        {
            "id": "textbox1",
            "name": "textbox1",
            "fieldType": "TextBox",
            "pageNumber": 1,
            "bounds": {"x": 100, "y": 100, "width": 200, "height": 200},
            "isRequired": True,
            "validationType": "CustomRegex",
            "validationCustomRegex": "^\\d+$",
            "validationCustomRegexMessage": "Enter numbers only",
        }
    ],
    "locale": "EN",
}

payload = {
    "Signers": json.dumps(signer_data),
    "Title": "Agreement",
}

files = [("Files", ("{file name}", open("{file path}", "rb"), "application/pdf"))]

headers = {"accept": "application/json", "X-API-KEY": "{Your API key}"}

response = requests.post(url, headers=headers, data=payload, files=files)

print(response.text)
```

```
const axios = require("axios");
const FormData = require("form-data");
const fs = require("fs");

let data = new FormData();

data.append(
  "Signers",
  '{\r\n        "name": "starvritsa",\r\n        "emailAddress": "starvritsabuhungi@syncfusion.com",\r\n        "signerType": "Signer", \r\n        "signerRole": "Signer",\r\n        "formFields": [\r\n           {\r\n                "id": "textbox1",\r\n                "name": "textbox1",\r\n                "fieldType": "TextBox",\r\n                "pageNumber": 1,\r\n                "bounds": {\r\n                  "x": 100,\r\n                  "y": 100,\r\n                  "width": 125,\r\n                  "height": 25\r\n                   },\r\n      "isRequired": true,\r\n    "validationType":"CustomRegex",\r\n  "validationCustomRegex":"^\\d+$",\r\n  "validationCustomRegexMessage":"Enter numbers only"\r\n  }\r\n  ],\r\n  "locale": "EN"\r\n}',
);

data.append("Files", fs.createReadStream("{you file path}"));

data.append("Title", "Node JS validation");

let config = {
  method: "post",
  maxBodyLength: Infinity,
  url: "https://api.boldsign.com/v1/document/send",
  headers: {
    "accept": "application/json",
    "X-API-KEY": "{your api key}",
    ...data.getHeaders(),
  },
  data: data,
};

axios
  .request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });
```

```
<?php
require_once "vendor/autoload.php";
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use \GuzzleHttp\Psr7\Utils;

$client = new GuzzleHttp\Client([
    'verify' => false,
]);

$headers = [
    'accept' => 'application/json',
    'X-API-KEY' => '{your Api Key}'
];

$options = [
    'multipart' => [
        [
            'name' => 'Message',
            'contents' => 'please sign the document'
        ],
        [
            'name' => 'Signers',
            'contents' => '{
                "name": "starvritsa",
                "emailAddress": "starvritsabuhungi@boldsign.dev",
                "signerType": "Signer",
                "formFields": [
                    {
                        "id": "textbox1",
                        "name": "textbox1",
                        "fieldType": "TextBox",
                        "pageNumber": 1,
                        "bounds": {
                            "x": 50,
                            "y": 50,
                            "width": 1,
                            "height": 1
                        },
                        "isRequired": true,
                        "validationType": "CustomRegex",
                        "validationCustomRegex": "^\\d+$",
                        "validationCustomRegexMessage": "Enter number only"
                    }
                ],
                "locale": "EN"
            }'
        ],
        [
            'name' => 'Files',
            'contents' => Utils::tryFopen('{file path}', 'r'),
            'filename' => '{file name}',
            'headers' => [
                'Content-Type' => 'application/pdf'
            ]
        ],
        [
            'name' => 'Title',
            'contents' => 'Autoreminder'
        ],
    ]
];

$request = new Request('POST', 'https://api.boldsign.com/v1/document/send', $headers);
$res = $client->sendAsync($request, $options)->wait();
echo $res->getBody();
```

## Conclusion

Regex validation acts as a gatekeeper, allowing only the correct data into your documents. With the BoldSign API, using regex means a smoother experience for both signers and document owners. Follow the examples in this blog and experiment with different scenarios to enhance your document signing workflows.

Start your [30-day free trial of BoldSign](https://account.boldsign.com/signup?planId=1018\&utm_source=boldsignblogs\&utm_medium=redirect\&utm_campaign=boldsign) today to see how it makes document creation and electronic signing easier. We value your feedback, so please share your thoughts in the comments below. If you have any questions or need more information about our services, don’t hesitate to [schedule a demo](https://boldsign.com/request-demo.md) or contact our support team through our [support portal](https://support.boldsign.com/support/tickets/create).

Topics [API integration](https://boldsign.com/blogs/tag/api-integration.md)[Getting started](https://boldsign.com/blogs/tag/getting-started.md)

## Sign documents 3x faster

Send, sign and manage documents securely and efficiently.

[Try it today](https://account.boldsign.com/signup?planId=1018\&utm_source=boldsignblogs\&utm_medium=redirect\&utm_campaign=boldsign)

## Starvritsa Buhungi

Starvritsa is a Technical Assistant at BoldSign, channelling her passion into crafting top-tier content for users through meticulous documentation. She creates content across various formats, including API tutorials, help articles, and comprehensive guides.

[More posts by Starvritsa Buhungi](https://boldsign.com/author/starvritsa-buhungi/)

## Related posts

- [General](https://boldsign.com/category/general.md) November 5, 2024 16 min read

  ## [How to Use BoldSign OAuth 2.0 for Seamless Application Integration](https://boldsign.com/blogs/oauth-2-0-application-integration.md)

  Learn how to integrate BoldSign OAuth 2.0 for secure access and authorization across applications, simplifying authentication without sharing credentials.

- [API](https://boldsign.com/category/api.md) September 29, 2026 10 min read

  ## [How to Migrate from Docusign Without Losing Templates or Workflow Continuity](https://boldsign.com/blogs/migrate-from-docusign.md)

  Learn how to migrate from Docusign while protecting templates, signed records, and active workflows. Explore key risks, a practical checklist, and next steps.

- [API](https://boldsign.com/category/api.md) September 25, 2026 10 min read

  ## [Build vs Buy an eSignature API: What Should You Choose?](https://boldsign.com/blogs/build-vs-buy-esignature-api-guide.md)

  Compare the real cost, compliance risk, launch speed, and maintenance burden of building vs buying an eSignature API before you commit.

Get started

## Sign up for your free trial today!

[Start free trial](https://account.boldsign.com/signup?planId=1018)

- 30-day free trial
- No credit card required

*Picture: A completed employment contract: signed by John Doe on 11/03/2026, all parties have signed*
