0

Im trying to generate an Google Spreadsheet Template with some Validation with their API, using the Node.Js Package from Google.

This is my current Request:

{
 "setDataValidation": {
    "range": {
      "sheetId": 1656514345,
      "startRowIndex": 0,
      "endRowIndex": 0,
      "startColumnIndex": 1,
      "endColumnIndex": 1000
    },
    "rule": {
      "condition": {
        "type": "CUSTOM_FORMULA",
        "values": [
          {
            "userEnteredValue": "=REGEXMATCH(TO_TEXT(A2:A1000); '([1-9]){4}[-]([1-9]){2}[-]([1-9]){2}$')"
          }
        ]
      },
      "inputMessage": "TEST VALIDATION",
      "strict": true
    }
  }

}

I get the following Error:

Error: Invalid requests[0].setDataValidation: Invalid ConditionValue.userEnteredValue: =REGEXMATCH(TO_TEXT(A2:A1000); '([1-9]){4}[-]([1-9]){2}[-]([1-9]){2}$')

A simple create or append Data in the Spreadsheet works fine, but getting an Regex Validation to work seems like the limit. In the Documentation there seems no limitation for RegEx, what is wrong with my Request?

Thanks in Advance.

sHamann
  • 789
  • 3
  • 10
  • 36

1 Answers1

1

Your expression needs to be escaped.

"userEnteredValue": "=REGEXMATCH(TO_TEXT(A1), \"[0-9]{4}[-][0-9]{2}[-][0-9]{2}$\")"

Note that the internal quotes are escaped (\" instead of ").

Note that single quotes also won't work.

ZektorH
  • 2,680
  • 1
  • 7
  • 20
  • Yeah, That worked, Thank You! Is it possible to add Cell Validation on a Create Call, or only on an Update call? If not, is there a way to get the spreadsheetId and sheetId of the creat call? – sHamann Nov 21 '19 at 21:38
  • @sHamann Please search on the documentation for information or submit a new question. – ZektorH Nov 22 '19 at 08:47