Jump to content

Return elements of an array unless they contain a PO Box


lasdoog

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...