Validating Single Test Field in Repeating Section with multiple regular expressions

  • 17 January 2018
  • 8 replies
  • 5 views

Badge +8

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})(.{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


8 replies

Userlevel 5
Badge +14

what is a "PO" variable(?) used in getElementById? where/how do you populate it?

is PO type selector within or out of repeating section?

Badge +8

PO is another JavaScript ID from a Choice Control to identify if the PO Numbers are going to be of Type AL or GL. This is Outside of the repeating section.

Userlevel 5
Badge +14

first of all update definition of regular expressions as follows

 var ALRegEx = new RegExp(/(^["]d{2})(.{1,5}["])$|(^["]MAL)(.{1,5}["])$/gm);
var GLRegEx = new RegExp(/^(.{1,7})$|(^MGL)(.{1,5})$/gm);‍‍‍‍

the second, I would say your regular expressions still needs a bit "tuning".

I do not know what exact format of PO numbers are acceptable and what not, but your regular expressions accept some suspicious inputs.

eg. pattern  ".{m,n}" as well accepts single space characters as valid PO number.

pattern "^(.{1,7})" fully overrule its alternative pattern "(^MGL)(.{1,5})"

the same input might be accepted for both PO number types

etc.

see some examples

212280_pastedImage_1.png

212281_pastedImage_2.png

custom validation‌ javascript‌

Badge +8

Thank you for your reply, so just as more information currently our format are:

AL: (2 digits followed by A then 1-5 digits or characters) or (first three need to be MAL followed by 1-5 digits or characters)

GL: (1-7 digits or characters) or (first three need to be MGL followed by 1-5 digits or characters)

 

When I hardcode a correct or incorrect PO number in the expression work as intended, just seems when i do it from the arugments.value, i see it putting the correct entry in but just always fails the validation.

Userlevel 5
Badge +14

digits or characters

then I would definitely replaced all dots with w ...

i see it putting the correct entry in but just always fails the validation

can you post an example?

Badge +8

Here are some screen shots:

212303_pastedImage_3.png

212287_pastedImage_2.png

212304_pastedImage_4.png

so as it shows it evaluates it shows the right value but will jump down to the else and set the IsValid to False versus Setting it to True.

Userlevel 5
Badge +14

that's correct happy.png

your regex pattern says valid input would be a string that starts with explicit quote sign, followed by string MAL, followed by 1 to 5 arbitrary signs and ending by explicit quote sign.

see my examples above.

quotes that debugger show just denote input is a string, they are not contained within input string/value.

Badge +8

Thanks a lot , everything is working nicely.

Reply