Select to view content in your preferred language

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

01-10-2022 08:59 AM
New Contributor III


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:



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) :


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

3 Replies
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,
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.

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,