Reject entry of specific text value

2612
7
Jump to solution
04-20-2021 07:42 PM
JulietK
Occasional Contributor II

Hi, I'm wanting to have a text field in Survey123, but would like to restrict the type of value entered. 

I'd like the field to be restricted to prevent entering of specific words, such as:

  • Unknown
  • None
  • Don't know

I saw that you could use regex in the constraint field, such as 

not(regex(.,"KNOW"))

which prevents entry of both UNKNOWN and DON'T KNOW but I haven't been able to figure out how to constrain by multiple values. I've tried using OR within the regex as well as having two regex formulas [  e.g. not(regex(.,"KNOW")) OR not(regex(.,"NONE"))  ] but they didn't work. 

How could I prevent form submission containing multiple specific words? 

I won't be able to constrain just by "NO" because this will likely be used in other wording.

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hi @JulietK,

Yes, the link to that blog is a good starting point for creating your pulldata() expression. You can also refer to the online documentation here.

The constraint expression needs to go on the original text question they are typing the answer into, not on the pulldata() question that is hidden. The pulldata question will just have the value in it returned from CSV. It can be hidden and null field type if you do not want to store the value in feature layer in a field. Also note that pulldata is case sensitive, so you need every combination added depending on the text they are typing. It msut be an exact match.

To make it easier to explain I just created a quick example, here are some screenshots:

Philip-Wilson_0-1619059829343.png

Philip-Wilson_1-1619059855644.png

Philip-Wilson_2-1619059880537.png

Philip-Wilson_3-1619060103489.png

I have not made the pulldata expression text field hidden, just for demo purposes, but in your final survey design, you can use hidden appearance or hidden question type, and set the esri field type to null if preferred.

Attached are the example files if you want to test it out.

There are likely other ways you can can achieve what you are wanting to do, either using regex expressions, nested if statements, pulldata or a combination of all three. It really depends how perfect you want the solution to be.

This approach could be used as a spell check, prvovided you have a well known list of all the words you want to allow. But in that case, if you do have a list of known words, I would suggest using a choice list via a select one question type, and using the autocomplete appearance, that way the user can select the words from a dropdown or type it in to select the well known values from the list and they must match to be valid. Choice lists are the best way to manage and control the extact text that is allowed to be entered.

Hope this helps.

Phil.

View solution in original post

0 Kudos
7 Replies
by Anonymous User
Not applicable

Hi @JulietK,

Instead of trying to use a regex or constraint that may become complicated to compile, a better way to do this would be to a use pulldata() @ CSV expression.

If you create a CSV with the words listed that you do not want the user to enter, you can then create a hidden text question with a pulldata() expression that points to the CSV. Pass the value they enter into the pulldata expression, and then check it against the field in the CSV. Have an additional field in the CSV against all the words that will return a value (this could be a number, or true/false string, whatever you want).

If the word they enter exists in the CSV file, that value is returned into the hidden text field. You then build the constraint on the original text question to use this value and provide an error message and make the constraint invalid when that word is used. This will be the easiest and cleanest way to display the message.

Note this will only work if they enter the exact word that matches, so if they use a combination of words or letters, unless it is on the list it will not match.

Hope this helps.

Regards,

Phil.

0 Kudos
JulietK
Occasional Contributor II

Hi Philip,

This sounds like a good solution, thank you for that! 

Just wondering where I can find more information on how to implement this (the formula/syntax)? 

I found this but it doesnt seem to show instructions on how to return an error if an entry matches content of the csv. 

If entries can be checked against a csv list, could it possibly also function as spell check? 

0 Kudos
by Anonymous User
Not applicable

Hi @JulietK,

Yes, the link to that blog is a good starting point for creating your pulldata() expression. You can also refer to the online documentation here.

The constraint expression needs to go on the original text question they are typing the answer into, not on the pulldata() question that is hidden. The pulldata question will just have the value in it returned from CSV. It can be hidden and null field type if you do not want to store the value in feature layer in a field. Also note that pulldata is case sensitive, so you need every combination added depending on the text they are typing. It msut be an exact match.

To make it easier to explain I just created a quick example, here are some screenshots:

Philip-Wilson_0-1619059829343.png

Philip-Wilson_1-1619059855644.png

Philip-Wilson_2-1619059880537.png

Philip-Wilson_3-1619060103489.png

I have not made the pulldata expression text field hidden, just for demo purposes, but in your final survey design, you can use hidden appearance or hidden question type, and set the esri field type to null if preferred.

Attached are the example files if you want to test it out.

There are likely other ways you can can achieve what you are wanting to do, either using regex expressions, nested if statements, pulldata or a combination of all three. It really depends how perfect you want the solution to be.

This approach could be used as a spell check, prvovided you have a well known list of all the words you want to allow. But in that case, if you do have a list of known words, I would suggest using a choice list via a select one question type, and using the autocomplete appearance, that way the user can select the words from a dropdown or type it in to select the well known values from the list and they must match to be valid. Choice lists are the best way to manage and control the extact text that is allowed to be entered.

Hope this helps.

Phil.

0 Kudos
JulietK
Occasional Contributor II

Hi Philip, 

This is very helpful, thank you so much for the detailed instructions! 🙂

 

JulietK
Occasional Contributor II

Ah forgot to mention, I am unable to use select_one option for this since the choice list would have to be updated/changed often, and sometimes entry of unexpected words/names would be required. 

 

I have a related query -

How would I apply the above solution, so that an error is returned if a specific word out of multiple words (separated by comma) in a text field doesn't match words in the csv file?

For example, I have a field which is a text field 'Species Name', which asks the user to write the species names such as 'Rabbit', 'Fox', 'Frog', 'Eagle' etc. This is because the text field for species cannot be a select_one or select_multiple, since multiple species data need to be entered and a very long list of select_multiple cannot be reduced to 'autocomplete' appearance. The field asks the user to write each word separated by a comma, for example 'RABBIT,FOX,FROG'.

If I used pulldata constraint for the 'Species Name', would it allow the user to enter multiple values  but return error if a value not matching any in the csv file is present?

 

0 Kudos
by Anonymous User
Not applicable

Hi @JulietK,

Based on what you are trying to achieve with just a straight text question and varying user input, there is no easy way to do a spell check or word match using pulldata() or other expressions supported in Survey123 and XLSForm. There are too many variables in the way a user may enter values; with spaces, without spaces, with commas, without commas, plus the issue with case sensitive and typos.

I think you should reconsider how you are designing your survey. Use a select multiple or a repeat with a select one question with autocomplete would be the best way to do this. Another option is to have mutliple select one questions that are relevant based on the last one being answered, so once they select one answer from dropdown with autocomplete, add another question to select another answer, and keep going up to a maximum amount, or use a repeat and do the same thing. You can then join them all the answers togehter in a single hidden text field if you need the data stored that way using a calculation. This means you can make the most of smart forms and data validation in the way they are intended.

Regards,

Phil.

0 Kudos
JulietK
Occasional Contributor II

Ah I see, so I'm guessing the full content of the field needs to match with any examples in the csv file when using the pulldata method. 

Unfortunately I am quite limited in what method I can use in this situation since this section of the survey is already in a repeat, and nested repeats don't work on the web form. The multiple select questions could be great though if I am able to find the maximum number I could set for the entries, I could look into this.

Thank you again!