Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
2

Wildcard Use in a Text Field Validate Property Custom Javascript

Community Beginner ,
Oct 05, 2023 Oct 05, 2023

I am attempting to have a Radio button checked based on text in a text field. The text field is named "E-mail Address", the Radio Button Group is named "Designation" and has three choice, "Military", "Civilian", or "Contractor". Our email addresses have a unique component to them based on the designation of the person, so they always have, and only one, of the below text strings.  

  - If the E-mail Address field contains ".mil@", check the "Military" Radio Button,

  - If the E-mail Address field contains ".civ@:, check the "Civilian" Radio Button,

  - If the E-mail Address field contains ".ctr@:, check the "Contractor" Radio Button.

      (If they don't have any of these text strings, no choice is checked in the Designation Radio Button and they will manually check the correct box, that is okay.)

Because these are email addresses, there will always be text before and after the specific text string I am validating against, but there is no defined pattern to the text.

I have it working to point that if only ".mil@", ".civ@", or ".ctr@" is entered into the E-mail Address field (no other text in the field) then the correct Radio Button is checked. However, if any additional text is entered into the E-mail Address field, it doesn't work. I can't figure out the wildcard charactor and assocated formatting. 

How do I add a wildcard character so that the Validation works with any text before and after the specific text string I am validating against? Thank you in advance for your assistance.

 

Here is the JS code I entered into the JS editor of the Validate tab as a Run custom validation script of the E-mail Address text field):

if( event.value == ".mil@")this.getField("Designation").value = "Military";

if( event.value == ".civ@")this.getField("Designation").value = "Civilian";

if( event.value == ".ctr@")this.getField("Designation").value = "Contractor";

 

TOPICS
JavaScript , PDF
592
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Oct 05, 2023 Oct 05, 2023

As Validate script of email field use this:

 

var str = event.value;
var pattern = /\.(mil|civ|ctr)@/;
var matchResult = str.match(pattern);
if(matchResult){
var matchedString = matchResult[0];
if(matchedString === ".mil@")
this.getField("Designation").value = "Military";
else if(matchedString === ".civ@")
this.getField("Designation").value = "Civilian";
else if(matchedString === ".ctr@")
this.getField("Designation").value = "Contractor";}

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2023 Oct 05, 2023

As Validate script of email field use this:

 

var str = event.value;
var pattern = /\.(mil|civ|ctr)@/;
var matchResult = str.match(pattern);
if(matchResult){
var matchedString = matchResult[0];
if(matchedString === ".mil@")
this.getField("Designation").value = "Military";
else if(matchedString === ".civ@")
this.getField("Designation").value = "Civilian";
else if(matchedString === ".ctr@")
this.getField("Designation").value = "Contractor";}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 05, 2023 Oct 05, 2023
LATEST

Worked perfectly, thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines