Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Default other/specify option text box to accept only numeric values

Good morning, everyone, hope you are doing well.

Currently using Lighthouse Studio, version 9.3.1.

I have a standard single select question type, where it has a Respondent specify ("Other Specify") option. Currently, the textbox accepts all kinds of values. However, I would like to configure the textbox to accept only numeric values. I know it is using the Custom Javascript Verification, but can't recall about the code. Can you help me out with this issue?

Thanks a lot for your time.

Best Regards,

Mauricio.
asked May 10, 2017 by Mauricio Belleza Bronze (860 points)
retagged May 10, 2017 by Walter Williams

2 Answers

+1 vote
Custom JavaScript verification is the way to go:

var resp = SSI_GetValue('[% QuestionName() %]_3_other');
var regex = /[0-9]+/;
if (resp && !regex.test(resp)) {
    strErrorMessage = 'Error.';
}


In line 1, replace the "3" with the item number of the other specify.  Line 2 may need to be replaced depending on exactly what inputs you want to accept:

var regex = /[0-9]+/; // any number of numeric characters
var regex = /-?[0-9]+/; // an optional negative sign, then any number of numeric characters
var regex = /([0-9]+.?[0-9]*)|([0-9]*.?[0-9]+)/; // one or more numeric characters with an optional decimal point


Hopefully one of those regular expressions is acceptable for you.  If you provide exact requirements of what inputs are okay, I can create the necessary regex for you.
answered May 10, 2017 by Zachary Platinum Sawtooth Software, Inc. (216,800 points)
Numeric with comma
0 votes
This is what I use for that purpose.  Just replace questionname with the name of your other specify variable and the number with the code where the other specify is assigned.  This code assumes the other specify was option 1.

var check=SSI_GetValue("questionname_1_other");
if(isNaN(check))
{
var strErrorMessage="Answer must be numeric"; }
answered May 10, 2017 by Jay Rutherford Platinum (53,270 points)
that's great
other specify not working
...