🔢Numeric validation
Add functionalities to open answers for numeric validation, stablish a min ad max value and other useful functionalities.
The following code is desing to add validation to open text inputs. This way, you can set a limit of digits, a maximum and a minumux amount as well.
First, you need to add an open text question where you want to add numeric validation.

Then, paste the code below and click the save button.
List of variables
question_code
The question ID of the text input you want to convert
min_val
The minimum value to accept No value: Default value is set to 0.
max_val
The maximum value to accept No value: Default value is set to +infinity.
max_length
The maximum amount of digits
How to use it...
Legacy code: The following codes works but have a drawback. If you type and click the next button fast, the text will not be properly deleted and we will recollect text instead numbers.
Version 1: Basic numeric open ended
One of the common case of use, is when you need to get numeric data from the respondent, i.e., to get the age, a quantity or an amount of money. This is when data validation comes to our part because SynoSurveys don't parse text to integers directly.
Affortunately, we have the following code to accept only numeric inputs in every single open ended question in the current page.
Warning: This code will remove strings on all the open ended questions that appear in the page. To be more specific, use the version 2 instead.
Version 2: Advanced numeric open ended
Sometimes, you will need to parse just one free answer to allow numeric values. In that case, you will need to use this code. To apply this parsing you need to pass the question code to the function when it's run.
Last updated
Was this helpful?