Have an idea?

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

Require 5 numbers for ZIP Code numeric question

Hi all,

we are asking respondents to type in their 5-character ZIP code in a numeric question. We would like to force respondents to insert exactly 5 numbers, no other characters. Since the ZIP codes of interest can also contain zeros in the beginning, e.g. 00045, it is not possible to use the min/max value provided within the tool.
Is there a way to require exactly 5 numbers in a numeric question?

asked Oct 26, 2020 by Joana

1 Answer

0 votes
Numeric questions automatically trim leading zeros.  What I'd recommend is using an open-end question instead, with this custom JavaScript verification to require responses to be exactly five numeric characters:

if (!/^\d{5}$/.test($('#[% QuestionName() %]').val().trim())) {
    strErrorMessage = 'Error message...';
answered Oct 26, 2020 by Zachary Platinum Sawtooth Software, Inc. (206,075 points)