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

Chuck Tomasi
Tera Patron

Can you provide an example of the text you are trying to parse? I'm not sure I fully understand the issue. (There may be other solutions based on what the underlying requirement is.)



What would you like to do with the information once it is parsed? Is it being validated that the questions are answered?



It would seem to be easier to use two question fields and two answer fields, or if the list varies in length, how about a table that can be used as a related list?


Hi Chuck



The whole idea for parsing is to validate if both questions had been answered or not , having two diff fields are not feasible ATM.



Example of quetions


1)What steps has been taken to resolve the issue



2)What steps has been taken to conrfirm issue never reoccurs


Is the question text always EXACTLY the same every time?


Yes, its the same always