0

I am building an incredibly large and complex integration with DocuSign using their eSignature API. As part of this we are providing MANY fillable fields on a DocuSign form. I can pass a validation pattern (regex) to the DocuSign API for a field and it will do validation based on that pattern. The issue I have run into, is any time that I need to use a '\' in my regex. From what it seems, to make valid JSON, there must be an even number of \ for example '\\d' - but this doesn't make for a valid regex and so, nothing will satisfy it.

How can I build Regex that require a \ in them and send them via JSON. The charachters that I definitely need are periods and dashes, which I don't know how to show in a regex without the \ delimiter before them.

After finding that my code was having issues with these erorrs, I started playing around in post man experimenting. I've searched online but most anywhere I search it says that regex is code and that it shouldn't be sent. Of course if I had power over both sides I could remove the extra delimiter on the DocuSign side but because I don't have this power to manipulate the payload on the receiving side, I'm stuck.

//Here is an example of something that I would LIKE to sent via JSON, but my single '\-' on the validation pattern are making it not valid JSON and returning an error. 

{
                "xPosition": "41",
                "recipientId": "1",
                "validationPattern": "^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$",
                "validationMessage": "Please enter a 10-digit telephone number. (###-###-####)",
                "documentId": "19305",
                "fontColor": "Black",
                "tabLabel": "partPhone",
                "shared": "false",
                "font": "ArialNarrow",
                "name": "Telephone Number",
                "locked": "false",
                "required": "true",
                "pageNumber": "1",
                "yPosition": "329",
                "fontSize": "Size10",
                "disableAutoSize": "false",
                "width": "161"
            }

I expect to be able to send the example snippet to DocuSign and there be no error, further more, I expect the Regex that I pass to it when including \ to actually work properly.

plum 0
  • 652
  • 9
  • 21
T. Ladd
  • 3
  • 1
  • Are you hand-writing JSON? If you encode your JSON using a standard library then the receiving end should be able to decode it no problem... – MonkeyZeus Aug 01 '19 at 19:36
  • You could encode hex encode them or you could escape them like \- and then you could just decode them when you want to use them (https://stackoverflow.com/a/17597400/2226328) – Frankenmint Aug 01 '19 at 22:52

1 Answers1

0

I agree with @MonkeyZeus -- there is no problem sending a backslash via JSON. To send a backslash, escape it with a backslash. See this source.

So, to use the regex 

^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$

Send the JSON equivalent string in your API request:

"^[0-9]{3}\\-[0-9]{3}\\-[0-9]{4}$"

Please update your question with an example of the JSON sent to DocuSign and the API response. Use the logger to get the trace.

Meanwhile:

  • DocuSign Regex uses the .NET implementation. Docs. I don't believe that we support substitution, just match or not match.
  • An online .Net regex tester
Larry K
  • 47,808
  • 15
  • 87
  • 140