The BoldSign mobile app is now available. Visitthis link for more details and give it a try!

The BoldSign mobile app is now available. Visitthis link for more details and give it a try!

Request Demo
BoldSign Logo Small

Features

Explore the BoldSign features that make eSigning easier.

How to Use Regex Validation via the BoldSign API Banner Image

How to Use Regex for Data Validation in the BoldSign API

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 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 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

    
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}' \

C#

    
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<IDocumentFile>
{
    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<FormField>()
{
    signatureField
};
 
var signer = new DocumentSigner(
  signerName: "David",
  signerType: SignerType.Signer,
  signerEmail: "starvritsabuhungi@boldsign.dev",
  formFields: formFieldCollections,
  locale: Locales.EN);
 
var documentSigners = new List<DocumentSigner>()
{
    signer
};
 
var sendForSign = new SendForSign()
{
   Message = "please sign this",
   Title = "Agreement",
   Signers = documentSigners,
   Files = filesToUpload,
 
};
var documentCreated = documentClient.SendDocument(sendForSign);

Python

    
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)

Node JS

    
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

    
<?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 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 or contact our support team through our support portal.
Picture of Starvritsa Buhungi

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.

Share this blog

Picture of Starvritsa Buhungi

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.

Subscribe RSS feed

Leave a Reply

Your email address will not be published. Required fields are marked *