Parsing Values in Text Field

avinash21
Mega Contributor

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

1 ACCEPTED SOLUTION

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]);


View solution in original post

6 REPLIES 6

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]);


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