- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2016 05:34 AM
Hi
I have a text field and it has 2 questions for example like below
Question 1
Question 2
Now I have to validate that both questions are answered , both Questions have question text , how this can be done ?
TIA
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2016 06:05 AM
You COULD do it with a regular expression similar to what I have below (and check for both answer[1] and answer[2] to be non-empty/non-undefined values. The thing is, if someone messes with your text, the pattern fails and they won't be able to continue. This is why I recommend two fields. That being said, here's a RegEx that should do what you want as long as they don't mess with your questions.
var input='1)What steps has been taken to resolve the issue\n' +
'None\n'+
'2)What steps has been taken to confirm issue never reoccurs\n' +
'Eat more vegetables\n';
var patt = /1\)What steps has been taken to resolve the issue\n(.*)\n2\)What steps has been taken to confirm issue never reoccurs\n(.*)\n/;
var answers = input.match(patt);
gs.print(input);
gs.print(answers.length);
gs.print('answer1=' + answers[1]);
gs.print('answer2=' + answers[2]);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2016 06:05 AM
You COULD do it with a regular expression similar to what I have below (and check for both answer[1] and answer[2] to be non-empty/non-undefined values. The thing is, if someone messes with your text, the pattern fails and they won't be able to continue. This is why I recommend two fields. That being said, here's a RegEx that should do what you want as long as they don't mess with your questions.
var input='1)What steps has been taken to resolve the issue\n' +
'None\n'+
'2)What steps has been taken to confirm issue never reoccurs\n' +
'Eat more vegetables\n';
var patt = /1\)What steps has been taken to resolve the issue\n(.*)\n2\)What steps has been taken to confirm issue never reoccurs\n(.*)\n/;
var answers = input.match(patt);
gs.print(input);
gs.print(answers.length);
gs.print('answer1=' + answers[1]);
gs.print('answer2=' + answers[2]);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2016 05:51 AM
If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
If you are viewing this from the community inbox you will not see the correct answer button. If so, please review How to Mark Answers Correct From Inbox View.
Thank you