Message Boards Message Boards

Back

How to check if the user input text contains specific words?

Toggle
I have a text input box and submit button on a page.

User submits their answer and I need to check if the text enetered by user contains any of these words "emotional", "physical"

User can input any of these forms - "Emotional" i.e. with an uppercase first letter, or "emotional" or "emotionally"

If the user input text contains both of the above words the I need to show "Correct". If only of those words, then I need to show "Parially correct". If none of those words then to show "Incorrect".

How do I achieve this?

Thanks
0 (0 Votes)

RE: How to check if the user input text contains specific words?
Answer
2/21/20 12:07 AM as a reply to D Singh.
Here's how to add an "or" block to look for multiple answers - https://www.screencast.com/t/f6QWBR7QKZ

Note that the "Text Input 1.contains" block only looks at whole words.  So it will not count "emotionally" as correct.  If you want to check for the contents regardless of whitespace (spaces), then you will want to use this block instead - https://www.screencast.com/t/y8cfezIyy

And you can use "and" and "or" blocks to check for specific combinations - https://www.screencast.com/t/L0oUvQJVXv

Finally, you can ignore CapiTaliZatioN by setting all the text to lowercase before it is evaluated - https://www.screencast.com/t/1PSgr58w

So your end result would look something like this:


Hope that helps!
0 (0 Votes)