Assistance With Numeric-Only Validation for “Age” Question

From the support desk

Steps to Reproduce the Problem: Hello SurveyEngine Support, I’m configuring a question on “Age (Years)” and I need to enforce numeric-only input.

I added a validation expression (as shown in the attached screenshot) and enabled the Validation option, but when I run Preview the rule doesn’t trigger—non-numeric input is still accepted and no error message appears.

Could you advise the correct steps to activate validation in Preview (e.g., any additional toggles, placement, or syntax requirements) and let me know if there are known limitations when validating text questions?

If possible, please also share the official reference for validation expressions (or a gallery of examples) so I can obtain the precise expression for integers within a range (e.g., 1–120). For context, this is in survey ”, page “” question label “Age,” and I can provide the PLAY/SURVEY IDs if needed. Thank you in advance for your guidance.

(attachments)


(attachments)


Simply - you are using unknown functions “toNumber”, “trim”, “floor” etc. These look like Java or Javascript. You also are not accessing the data lable which is $C2 not $this.

All expressions are in vanalla Perl, so you should adapt accordingly.

Since you are testing for values between 1 and 120 - you can just use a fairly loose test as all strings evaluate to zero.

($C2>=1 && $C2<=120)

Formally you should use regular expressions that look like this which test that it’s only digits

($C2=~/^\d+$/)

combined with the range

($C2=~/^\d+$/) && ($C2>=1 && $C2<=120)

But I woujld just use the first as it is a solid test that the values have a numerical evaluation as well as the correct range.

a good sanbox to test is Perl Online Compiler
cutitng and pasting the code below can verify the validation expression for different cases. Note that in Perl - any empty or zero value is evaluated as FALSE

# test C2 is in the range

# set it to a valid value
my $C2 = '99';

# print it out 
print "when C2 = $C2, result is [".($C2>=1 && $C2<=120). "]\n";
# in SurveyEngine use return ($C2>=1 && $C2<=120) for the validation

# set it to nonsense values
$C2 = '0';
print "when C2 = $C2, result is [".($C2>=1 && $C2<=120). "]\n";


# set it to nonsense values
$C2 = 'random stuff';
print "when C2 = $C2, result is [".($C2>=1 && $C2<=120). "]\n";