Validating Question Answers Using Regex

Now validate secondary scans, multiple choice answers, and text entries to collect accurate data using the codeREADr no-code/low-code SaaS platform

As we noted in this codeREADr blog article, we help customers improve the accuracy of their collected data. This is one of many initiatives for achieving that goal.

Periodically, we will share with our users custom validation scripts that we have created at a client’s request. One of our latest additions is a script for validating question answers using RegEx. Using this script, look for a designated pattern in data, such as a barcode scan, text entry, or text selection. A PDF of the script is here in the codeREADr Knowledgebase. Below are the instructions for the application.

Step 1

Create a service and collect data with questions as desired. The service must be on-device, not online.

service with questions

Note the question ID(s) for the questions you will be validating.

questionid

Step 2

On the advanced settings step, select “Enable on-device custom validation.” In the text box, you will copy and paste this script.

pasted script

Step 3

Edit the script so that var regex includes only the patterns you would like to use. New additions to the array should follow the following format:

“QUESTION_ID”: [new RegExp(“PATTERN”), “OPTIONAL ERROR MESSAGE”]

For example, if you want to validate that your question answer contains the string “abc”:

“1737556”: [new RegExp(“[\s\S]*abc[\s\S]*”), “This ID is not valid.”]

regex patterns

This COV script has a wide variety of uses from secondary ID validation to enabling proper procedures and protocol. Any RegEx pattern can be used to authenticate the given question answer. If you have trouble implementing this script or are unsure if it would work for your use case, contact us via email or LiveChat.