I was hoping to put in a constraint for all my text questions with the multiline appearance that will not allow a line feed (ie does not allow the user to hit enter and create a new line rather the user must use one continuous line with spaces and punctuation). I am not well educated in coding and cannot figure out using the regular expressions documentation. Any ideas on how I can accomplish this?
What I do not want:
"Apple
Banana
Pear"
What I do want:
"Apple, Banana, Pear"
Solved! Go to Solution.
Using regex is definitely the way to go. As I posted in a similar thread, you can use the following expression in the constraint column: not(regex(., '\n'))
I've tested this a bit in another survey and it seems to work well at preventing any line breaks. Just make sure you provide a descriptive constraint message so that users understand what's going on.
Hi Katherine,
I don't believe this is possible using a constraint or input mask. If you do not want users to use the multiline appearance as it is intended (to create line feeds or carriage returns in a single text box), I would suggest you use a text question type without multiline appearance so it appears in the survey as a single line text box and line feeds or carriage returns can not be used.
Phil.
Thanks for the reply. Is there any way that I could add an intermediate question that can return a number >=1 for the number of line feeds found or 0 if no line feed is found. If so then I can put a constraint on that question that it must be 0. This can accomplish what I would like. I would just need to know what expression to use to search for the line feed.
Hi Katherine,
I think the regex expression you would need to use in a constraint to find line breaks would need to include a \n or \r search which represent line breaks or carriage returns. You can find more info here about using regex in Survey123: Formulas—Survey123 for ArcGIS | ArcGIS and here is some more info on regex parameters Regex Cheat Sheet.
I haven't tested this myself, but have a play around and hopefully you can get it working the way you want.
Phil.
Using regex is definitely the way to go. As I posted in a similar thread, you can use the following expression in the constraint column: not(regex(., '\n'))
I've tested this a bit in another survey and it seems to work well at preventing any line breaks. Just make sure you provide a descriptive constraint message so that users understand what's going on.
This has worked out great for us, exactly what I was looking for!
Thank you so much!!!
Katie.