Have an idea?

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

*Forcing* respondent to enter decimals

Hello Sawtooth forum,

I am often asked to limit the number of decimals entered (for a price).
But here I was requested kind of the opposite, and I am struggling to make it work.

Basically, I want to force respondents to enter at least 2 decimals (it's OK if the enter e.g., 9.00, as long as they enter the .00).
i.e., if the entry does not include 2 decimals, I'd need to have an error message.

asked Mar 14 by amic Bronze (905 points)

1 Answer

+2 votes
Best answer
Assuming this is a numeric question, try this custom JavaScript verification:

if (!/\.\d{2}\s*$/.test($('#[% QuestionName() %]').val())) {
    strErrorMessage = 'Error message here.';
answered Mar 14 by Zachary Platinum Sawtooth Software, Inc. (108,875 points)
selected Mar 14 by amic
Works a treat.  I once again forgot to think about regex for the solution...

Thanks Zacary.