Select to view content in your preferred language

Can I restrict characters allowed in Survey123 text box?

4955
9
Jump to solution
12-04-2019 02:39 PM
BenVan_Kesteren1
Deactivated User

Hey, 

I have a comments field in a survey123 form, and I am wondering if I can make a comma an invalid/not allowed character?

The reason being is the data ends up being used in a CSV file, and this is causing headaches for me later on.

So my question is, can I deny users the capability to use a comma in a text field, in a Survey123 form?

0 Kudos
1 Solution

Accepted Solutions
JamesTedrick
Esri Esteemed Contributor

Hi Ben,

You can create a constraint that looks for commas and returns false when it finds one:

not(regex(., ","))

View solution in original post

9 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Ben,

You can create a constraint that looks for commas and returns false when it finds one:

not(regex(., ","))

BenVan_Kesteren1
Deactivated User

Hey James Tedrick

I am just trying out your suggestion, but it doesn't seem to be working for me, can you please see below setup and check I am doing it correctly?

I have added the not(regex(., ",")) which is having no effect it would seem.

Cheers

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Ben,

That's interesting - it's working for me.  Just to check, did you attempt to validate the form (which triggers the check for constraints)?

0 Kudos
BenVan_Kesteren1
Deactivated User

Sorry James I have just found my error, I was not being warned of my issue until I tried to press the submit button in my form. 

I was thinking I was going to get the warning as soon as I typed it in the box, and tabbed to next text box, but that was not the case. It only checks when trying to send data.

So thank you for your help, that is now working well.

0 Kudos
KellyAlexander
New Contributor

Hi James! If you wanted to set the constraint to prevent \ and / from being used how would you do that?  I was able to set the constraint for one of the characters but not both by just changing the code above to: not(regex(.,"/"))

BenVan_Kesteren
Occasional Contributor

Did you ever work out how to do this Kelly Alexander‌? I am now wanting to do the exact same thing!

0 Kudos
KellyAlexander
New Contributor

Nope, I ended up just blocking one of the characters but making the constraint message say both in hopes that it would deter the surveyor from trying to use it.  It has worked so far, but its obviously not a true solution.

constraintconstraint_message
not(regex(.,"/"))Do not use / or \

Ben Van Kesteren

0 Kudos
DurhamGIS
Occasional Contributor

@KellyAlexander @BenVan_Kesteren All,

Through several community posts and a lot of testing, I've strung together how to restrict multiple, but not all, special characters in a text field.  Specifically, to restrict \ /, use

not(regex(.,'[|\x5C/]'))

I restricted ' \ & @ ; " / ? + # $ using

not(regex(.,'[|\x27|\x5C&@;"/?+#$]'))

For a single quote ' and backslash \, I found to use |\x%% with %% corresponding to the URL encoding code for the special character.

To restrict use of all special characters and allow letters and numbers only, use

regex(.,'^[A-Za-z0-9]*$')

CBeck
by
Emerging Contributor

As a flow onto this (as I already have data with non-standard ASCII in it) what encoding is used in Survey123? If I have that I can fix the problem in the current data and use the above fix for the next round. 

0 Kudos