Admiral
Admiral
433 views

Can java or appscript test whether a string occurs once in a text field?

Jump to solution

I set a form action to show Field B if a text Field A contains a string.  I would like to hide Field B if the string only occurs once in Field A.  Can javascript or appscript accomplish this?

Labels (1)
Tags (3)
0 Likes
1 Solution

Accepted Solutions
Fleet Admiral
Fleet Admiral

this will determine if Field A has 1 occurrence of "the string" (in any case) and hide Field B if so, otherwise it will show field B. 

var matches = GetFieldValue("Field A").match(/the string/gi) ;
if ( matches !== null && matches.length === 1) {
   HideField("B");
} else {
   ShowField("B");
}

 

View solution in original post

0 Likes
7 Replies

Yes, definitely you can do such validations in java script / App script.

0 Likes
Admiral
Admiral

Thank you.  That's encouraging.  I wonder what would that look like in javascript and appscript.

0 Likes
You need to spilt the text field value by your string and check the length of your string array after split to take decision.
0 Likes
Admiral
Admiral
Thanks! And what would that look like?


0 Likes
Fleet Admiral
Fleet Admiral

this will determine if Field A has 1 occurrence of "the string" (in any case) and hide Field B if so, otherwise it will show field B. 

var matches = GetFieldValue("Field A").match(/the string/gi) ;
if ( matches !== null && matches.length === 1) {
   HideField("B");
} else {
   ShowField("B");
}

 

View solution in original post

0 Likes
Admiral
Admiral

Thank you.

Would the 'if' statement that follows test for field "B" as empty?

0 Likes
Admiral
Admiral

I suppose I could set another variable instead of hiding or showing field "B"?

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.