AnsweredAssumed Answered

Validating Single Test Field in Repeating Section with multiple regular expressions

Question asked by kkittinger on Jan 17, 2018
Latest reply on Jan 19, 2018 by kkittinger

Hello Community,

 

We have a form to do PO Numbers and those Number can be of AL or GL.  The user selects the type of PO numbers that will be entered and then starts to fill out a Repeating Section with those numbers. (This is do to depending on the type of POs they route to different people in the company that handles processing.)  We want to make sure they are entering the correct format for the numbers based on their selections.  We created the regular expressions for the AL and GL format that is needed based on the requirements that is gathered.  We have assigned a Store Client ID in JavaScript variable for the text box in the repeating section. When user moves out of the text box it calls a JavaScript function to do the validation. Even if you put in the correct format it still comes back as a bad validation.  Below is the JavaScript code we are using:

 

function InvalidPoNumber (source, arguments) {
 var ALRegEx = new RegExp('/(^["]\\d{2}[A])(.{1,5}["])$|(^["]MAL)(.{1,5}["])$/gm');
 var GLRegEx = new RegExp('/^(.{1,7})$|(^MGL)(.{1,5})$/gm');
 var selection = document.getElementById(PO).value;
 if (selection == "AL") {
  if (ALRegEx.test(arguments.Value)) {
   arguments.IsValid = true;
  } else {
   arguments.IsValid = false; }
  } else if( selection == "GL") {
  arguments.IsValid = GLRegEx.test(arguments.Value);
 }
}

 

Any help or other solutions would be greatly appreciated.

 

Thanks,

Kevin

Outcomes