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?
Solved! Go to Solution.
Hi Ben,
You can create a constraint that looks for commas and returns false when it finds one:
not(regex(., ","))
Hi Ben,
You can create a constraint that looks for commas and returns false when it finds one:
not(regex(., ","))
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
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.
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(.,"/"))
Did you ever work out how to do this Kelly Alexander? I am now wanting to do the exact same thing!
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.
constraint | constraint_message |
not(regex(.,"/")) | Do not use / or \ |
@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]*$')
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.