Select to view content in your preferred language

Web Designer Constraint regular expression fail to publish when using $ in regex

172
3
a week ago
Teresa_Blader
Frequent Contributor


In the Survey123 Web Designer constraints I want my string field to only include letters, numbers, and spaces. My understanding is that the regex would be: regex(.,'^[a-zA-Z0-9 ]+$')... however this fails to publish.

I'm entering this in the UI in Web Designer

^[a-zA-Z0-9 ]+$

I've tried many many different things and it seems like the fail happens because of how $ is being handled as is passes ^[a-zA-Z0-9 ]+$ from the UI to syntax. Excluding $ does not solve the issue - it publishes but passes the constraint no matter what is entered in the string.


Publishing seems to be taking what should be regex(.,'^[a-zA-Z0-9 ]+$') and turning it into regex(.,'^[a-zA-Z0-9 ]+)) and failing to publish.

.*['"].*

works in the opposite way... like the constraint would only pass if my string includes a special character. So don't want that.

Goal:

Santa's Workshop = fail the constraint and show the message

Santas Workshop = pass the constraint and allow to submit

So how would I get this to happen if I can't use $ in the syntax without moving to survey123 connect??

Teresa Blader
Olmsted County GIS
GIS Analyst - GIS Solutions
0 Kudos
3 Replies
Teresa_Blader
Frequent Contributor

Teresa_Blader_0-1761242972536.png


ERROR WHEN PUBLISHING:

  • 999: b"ODK Validate Errors:\n>> XForm is invalid. See above for the errors.\norg.javarosa.xform.parse.XFormParseException: bind for ${Theme} contains invalid constraint expression [regex(.,'^[a-zA-Z0-9 ]+))] Couldn't understand the expression starting at this point: regex(.,\xcd\x8e'^[a-zA-Z0-9 ]+...\n\nResult: Invalid"
Teresa Blader
Olmsted County GIS
GIS Analyst - GIS Solutions
0 Kudos
CodyPatterson
MVP Regular Contributor

Hey @Teresa_Blader 

Would it be possible to add the constraint in a hidden field?
https://community.esri.com/t5/arcgis-survey123-questions/hidden-field/td-p/845587

Once the hidden field is added, changing the default value to be this: "^[a-zA-Z0-9 ]+$" with quotes and everything, then once you're wanting to validate put in the validation section something like this: 

regex(., ${pattern_helper})

I believe that the formatting is causing the issue, but the variable reference may end up passing this validation check.

Cody

0 Kudos
Teresa_Blader
Frequent Contributor

That's such a great idea BUT regular expressions right now only allow "value" and "field" is not available in the dropdown 😭

Teresa_Blader_1-1761321234257.png

Teresa Blader
Olmsted County GIS
GIS Analyst - GIS Solutions
0 Kudos