title: How to restrict google forms submission based on two ID using GAS on Google Form or Google Sheets
body: <p>I'm working on a query Google Form which collects participants' votes to a certain question. I want to restrict participants based on the ID number. I was thinking of three approaches:</p>
  
  <ol>
  <li><p>Prevent form submission if the entered ID is not on the given list. (I prefer this approach but couldn't find any useful code for it so far)</p></li>
  <li><p>Delete rows in the linked responses spreadsheet after form submission using <em>GAS on Google Form</em> through onFormSubmit trigger. Here is my code which is not working:</p>
  
  <pre><code>function onFormSubmit(e) {
   // Grab the session data again so that we can match it to the user's choices.
  var response = [];
  var values = SpreadsheetApp.openById('1rT9tKAi6ZSvZzBaXNSPMJAt4RKnW- 
   9lqiE9zvZV').getDataRange().getValues();
  
  for (var i = 1; i &lt; values.length; i++) {
    var indiv = values[I];
    var Fname = indiv[0];
    var Lname = indiv[1];
    var ID1 = indiv[2];
    var ID2 = indiv[3];
  
    // For every selection in the response, find the matching ID1 and title
    // in the spreadsheet and add the session data to the response array.
    if (e.namedValues[ID1] == ID1) {
      response.push(indiv);
    } else {
    Browser.msgBox('Your ID number does not matches the list');
    }
  }
  </code></pre></li>
  <li><p>Delete rows in the linked responses spreadsheet after form submission using <em>GAS on Google Sheets</em> through onChange trigger. Here is my best effort:</p>
  
  <pre><code>function onChange(e) {  
   var refvalues = 
   SpreadsheetApp.getActive().getSheetByName('members_sheet').getDataRange().getValues();
   var  sheet = SpreadsheetApp.getActive().getSheetByName('Form Responses 1');
   var  values = sheet.getDataRange().getValues();
  
   var indiv = values[values.length];
   var ID1 = indiv[2];
   var flag = 0;
    for (var i = 1; i &lt; refvalues.length; i++) {
        var refindiv = refvalues[i];
        var refID1 = refindiv[2];
      if (ID1 == refID1) {
        flag = 1;
      }
   } 
  
   if (flag == 0) {
     sheet.deleteRow(values.length); 
   }
   };
  </code></pre></li>
  </ol>
  
  <p>I'm totally new in Javascript coding so any help would be appreciated.</p>
  
  <p>//-----------------------------------------------------------------------------//</p>
  
  <p>Thanks to the ziganotschka answer I update my code to this:</p>
  
  <pre><code>function makeMultiForm() {
    var form = FormApp.create('Nazar Sanji')
                  .setConfirmationMessage('Thank you! Your Vote have been 
      recorded');
    form.setTitle("Query");
  
    var ss = SpreadsheetApp.openById('1rT9tKAi6ZSvZzBaXNSPMJAt4RKnW- 
     9lqiE9zvZV5JJk');
    var ID1List = 
      ss.getSheetByName('members_sheet').getRange('C2:C4').getValues();//Ex [123 ; 555]
    var ID2List = 
      ss.getSheetByName('members_sheet').getRange('D2:D4').getValues();//Ex [aa ; bb]
  
    // Ex passwords: asd, 123, asd123
    const condition1 = ID1List.map(element =&gt; `${element}`).join('|')
  
    var IDarray =[];
    //Add items to IDarray Ex [123aa ; 555bb]
      for(var i=0; i&lt;ID1List.length; i++){
          IDarray[i] = [ID1List[i][0]+ID2List[i][0]];
      }
    const condition2 = IDarray.map(element =&gt; `${element}`).join('|')
  
    // Start by laying out the bare-bones structure.  This defines the different
    // sections, and the bare widgets in each section.
    // Note that you can't add any flow-routing details at this point, because
    // the destinations most likely haven't been defined yet
  
    var itemFName = form.addTextItem().setTitle('First Name').setRequired(true);
    var itemLName = form.addTextItem().setTitle('Last Name').setRequired(true);
    var itemID1   = form.addTextItem().setTitle('First ID').setRequired(true);
  
    // Create valid ation for this question matching the ID1(ID Melli) that we got from the sheet
    var ID1Validation = FormApp.createTextValidation()
  .setHelpText('Enter a Valid First ID')
  .requireTextMatchesPattern(condition1)
  .build();
    itemID1.setValidation(ID1Validation);
  
    //var sectID2 = form.addPageBreakItem().setTitle("Second ID");
    var itemID2 = form.addTextItem().setTitle('Second ID').setRequired(true);
  
    // Create valid ation for this question matching the ID2(ID Shenasnameh) that we got from the sheet
    var ID2Validation = FormApp.createTextValidation()
  .setHelpText('Second ID does not match the First ID')
  .requireTextMatchesPattern(condition2)
  .build();
    itemID2.setValidation(ID2Validation);
  
  
    var sectVote = form.addPageBreakItem().setTitle("Final Vote");
    var VoteOptions = form.addMultipleChoiceItem().setTitle("Which Competition");
    VoteOptions.setChoices([
    VoteOptions.createChoice("Option 1"),
    VoteOptions.createChoice("Option 2")]);
  
  }
  </code></pre>
  
  <p>The recent issue is on ID2validation. Since <em>condition2</em> is the concatenation of two ID numbers, the participant has to enter his/her merged ID's (passwords) in the last text item in the Google Form which is not correct. (Ex. '123aa')</p>
  
  <p>How can I fix this?</p>