DEV Community

Cover image for How to Use Regex for Data Validation in the BoldSign API
Dhinesh Sekar for BoldSign

Posted on • Originally published at boldsign.com

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 -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}' \
Enter fullscreen mode Exit fullscreen mode

Other programming languages — check it on the BoldSign blog page.

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.

Related blogs

Note: This blog was originally published at boldsign.com

Top comments (0)