lasdoog Posted June 30, 2023 Share Posted June 30, 2023 Hello, I'm using a script from the forum to feed values into an array and then return only the fields that contain an address. The problem is I don't want to return the field if the address is a PO Box. I've tried a number of things, but can't quit get there... Here's my script where it stands now: //Create array to deal with multiple options var listOptions = []; //declare array var outlaw = /^(?:Post(?:al)? (?:Office )?|P[. ]?O\.? )?Box(?:\s\d+)?$/i; for (i=1;i<=3;i++) { //setup loop to cycle through optional fields (must match number of fields) var option = Field("Address"+i); if ((option != "") && (option != outlaw)) { //if the optional field is not blank and doesn't contain "PO Box" then add to array listOptions.push(option); } } return listOptions.join(", "); //list the array values separated by comma + space Any advice is greatly appreciated! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted July 3, 2023 Share Posted July 3, 2023 Can you provide any sample data to test against? Quote Link to comment Share on other sites More sharing options...
lasdoog Posted July 3, 2023 Author Share Posted July 3, 2023 Sure! Here is a small dummy sample of what the data looks like. Thanks for your help! Dummy_Data.txt Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted July 3, 2023 Share Posted July 3, 2023 You're very close. The "if" line should be: if (option != "" && !outlaw.test(option)) { //if the optional field is not blank and doesn't contain "PO Box" then add to array You created a regular expression object to test against a string for a match, but you then have to call RegExp.test, or a similar method such as String.match, to check the string against the regular expression for a match. Quote Link to comment Share on other sites More sharing options...
lasdoog Posted July 3, 2023 Author Share Posted July 3, 2023 Thank you!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.