Creating a constraint for 3 digits after the decimal in Survey123

08-06-2019 04:25 PM
Occasional Contributor III

I'd like to constrain user input in a decimal field (esri type double) to look like -0.123.  That is: either negative or positive, one digit before and 3 digits after the decimal.

I've got the following regular expression as a constraint:

regex(., '^[-]?\d[.]\d{3}$')

This works, except it won't allow a number like -1.100

The last digit has to be non-zero. If I switch the type of the field to text, it evaluates correctly, but that makes for a much less nice keyboard input on the ipad for the user.  I would like to keep the numeric keyboard.

Any ideas?  I'm fine with allowing -1 or -1.1 but don't want to allow 100.  I would prefer that the user have to type all 3 digits after the decimal.  I prefer to have them type the 0 before the decimal if the value is less than 1, but that's negotiable as well.

Good Values:





Bad values:




-.123 (negotiable)

-1 (negotiable)


0 Kudos
5 Replies
Regular Contributor II

Have you looked at using an "Input Mask"?

Online help for this topic is located here:
Esri custom columns—Survey123 for ArcGIS | ArcGIS 

0 Kudos
Occasional Contributor III

Thanks Joe, I like the way this works for required characters. Making them type a positive sign is a bit of a nuisance but in this particular case (cathodic reads) they are almost always negative, so it really reinforces the point.  I think I'll use #9.999

I don't really understand how the optional characters work in the mask.  Can anyone explain? 

For example, I can't see to get a different validation for #9.999 than #9.900

From the description "ASCII digit permitted but not required" for 0, I thought that -1.2 would be a valid value for #9.900 but it says it's invalid.

0 Kudos
New Contributor III

Were you able to implement this successfully?  I'm stuck in a similar situation and trying to validate to 2 decimal places. Unfortunately, it feels like none of the solutions are great since validation doesn't happen until the very end of the form submission and/or there's some wonky requirements that require people to input 0s as characters just to pass validation instead of intuitively seeing 1.2 as 1.20, for example.

Nothing works very well from the end user perspective so I'm wondering what you ended up using.

0 Kudos
Occasional Contributor III

I ended up just using the bind::esri: #9.999   Although it requires the user to explicitly indicate a positive or negative sign, in the case of a cathodic read that was vaguely desirable anyway.  But I couldn't get the optional characters to work as I expected.

James' solution to validate with modular arithmetic seems preferable if you want to give the users the widest latitude of what set of characters they enter. 

0 Kudos
Esri Esteemed Contributor

Hi Erika,

Another way to multiply the number by the number of digits you are looking for and

- check to see if there is any decimal component left (${q}*1000 - int(${q})*1000) > 0

- check that the last digit is non-zero (${q}*1000) mod 10 > 0

0 Kudos