Regex Constraint issue with string length, when that is not part of the constraint

567
3
01-10-2022 08:59 AM
GrantZ
by
New Contributor III

Hi,

I'm having an issue implementing a constraint to a text field in a survey I'm designing. The string input can be any length, but it can only consist of the characters 0, 1, and 2. Any other character should throw a flag. What I've currently implemented is:

regex(.,'^[0-2]*$')

 

This tends to work -- however, it only works for the first two characters in the string. If the string is any longer than two characters, it throws the constraint flag (strangely, the error message appears like this, instead of tied to the question, as it usually does/should) :

GrantZ_0-1641833867517.png

I have no experience writing regex, so any help would be useful. Thank you!

3 Replies
ZacharySutherby
Esri Regular Contributor

Hello @GrantZ

Using regex(.,'[0-2][0-2][0-2]') would be one way to reach the regex you are looking for. 

 

Thank you,
Zach
GrantZ
by
New Contributor III

Thanks @ZacharySutherby. Is there a way to adapt this to account for a string of any length? The string that a user will enter could be any length.

ThomasHamill
Occasional Contributor II

@GrantZ, is the field type for the entry you're using the regex on a text/string field?  If so, Survey123 will give it a length of 255 characters by default in the hosted feature services it creates when the S123 form is published to ArcGIS Online, so I think you could adjust the regex to match this character length.

Kindest Regards,

t