PDA

View Full Version : Zip codes rule


gkaffka
April 6th, 2009, 09:24 PM
Hey all. I am so new at this and if this is a silly or stupid post, please advise me on this. With that said. I need a rule that will do the following

If a zip code is 12345 and has no ZIP 4 then leave it as is... BUT if the zip code is 12345 and has a zip 4 of 6789 then add a dash 12345-6789. Does this make sense? If so anyone throw me a bone and help me out??? Just started and my job and this part is new to me.. Thanks so much for any help.

:confused:

DSweet
April 7th, 2009, 06:23 AM
gkaffka,

If your zipcode is split into two fields with one being the normal 5 count and an additional field with the +4 count then use a rule such as this...
if (Trim(Field("plus4Code")) == "") {
return Field("zipcode");
}
else {
return Field("zipcode") + "-" + Field("plus4Code");
}
This would suffice for two separate entries for the zip code. However, if your zipcode is all one field then try this one...
if (Len(Field("zipcode")) = 5) {
return Field("zipcode");
}
else {
var zipLen = Len(Field("zipcode"));
return Left(Field("zipcode"), 5) + "-" + Right(Field("zipcode"), (zipLen -5));
}

You do need to be careful since there really is no checking of the data that is done within these rules. You need to be sure to know your data and whether or not they are all valid zipcode items. Also, this rule is only valid for U.S. zipcodes and those that are similar in their make-up (5 or more digits without spaces). If you tried to use this rule with any Canadian zipcodes mixed in with the list the rule would still work correctly, but the output would not be valid according to the Post Office.

gkaffka
April 7th, 2009, 09:20 AM
Thanks David.. That worked like a charm. I had to tweek to our name fields and it was right on. I am more of a graphics guy and I am now getting into the variable end. I was close, but missed a line or two..