Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Formatting Text


Thread Tools Search this Thread Display Modes
Old July 15th, 2011, 06:54 AM
JHester JHester is offline
Forum n00b
Join Date: Feb 2011
Location: Memphis, TN
Posts: 2
Default Need help with a city State Zip rule

Needing help with a rule that does the following:
For the city it needs to Force UC the first letter and force LC the remaining letters in the city with a comma coming directly after.
For the state it needs to Force UC the state initials with no comma after the state and before the zip.

Final format should look like this:
Cordova, TN 38018

I am still pretty new at all this so any help would be greatly appreciated.

Reply With Quote
Old July 15th, 2011, 08:07 AM
jwhittaker jwhittaker is offline
Senior Contributor
Join Date: Feb 2009
Location: San Diego
Posts: 158
Default Re: Need help with a city State Zip rule

Here is one way to do this. There are default text rules that will convert a field to proper case and all caps. You can use one of these rules for the city and one for the state. As far as the comma, you can create a new empty text rule and make a simple if then statement. If the state is not equal to nothing then return a comma and a space if there is nothing in the state field the return nothing. I'll attach a couple of screenshots with this. Good luck.
Attached Images
File Type: png Picture 2.png (28.7 KB, 23 views)
File Type: png Picture 5.png (26.6 KB, 17 views)
FusionPro VDP Creator 10.0.26 | MacOS 10.13.4 | Acrobat DC
Reply With Quote
Old July 18th, 2011, 07:30 AM
step's Avatar
step step is offline
Senior Contributor
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Need help with a city State Zip rule

This will format the fields as you have requested, however it won't take into account scenarios where the "city" field is blank and leaving you with something that looks like this: ", TN 55555".

return ToTitleCase(Field("City")) + ", " + ToUpper(Field("State")) + Field("Zip");
To address that issue try the following:

return (Field("City") != "") ? ToTitleCase(Field("City")) + ", " + ToUpper(Field("State")) + Field("Zip") : Field("Zip");
With the above code, it will only return the zip code if the city field is blank.
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

Reply With Quote
Old September 13th, 2016, 08:51 AM
ehigginbotham ehigginbotham is offline
Junior Community Member
Join Date: Jun 2009
Posts: 34
Default Re: Need help with a city State Zip rule

any advice on this if they are all in one field and you need to do the same thing?
CITY, STATE ZIP is the filed name.
Eric Higginbotham
FP 9.1.0 Windows 7
Reply With Quote
Old September 13th, 2016, 09:43 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,340
Default Re: Need help with a city State Zip rule

Originally Posted by ehigginbotham View Post
any advice on this if they are all in one field and you need to do the same thing?
CITY, STATE ZIP is the filed name.
That's the name of the field, or its format?

If the state name is spelled out, instead of a two-letter abbreviation, then you can simply apply ToTitleCase to the whole thing, like so:
return ToTitleCase(Field("CITY, STATE ZIP"));
If it has a two-letter state abbreviation, then this should work:
return Field("CITY, STATE ZIP").replace(/^(.*),\s*(\w{2})\s+([\d\-]+)$/, function(all,city,state,zip){ return ToTitleCase(city) + ", " + ToUpper(state) + " " + zip; });
If the state name can either be spelled out, or a two-letter abbreviation, you can use this code:
return Field("CITY, STATE ZIP").replace(/^(.*),\s*(\w+)\s+([\d\-]+)$/, function(all,city,state,zip){ return ToTitleCase(city) + ", " + (state.length > 2 ? ToTitleCase(state) : ToUpper(state)) + " " + zip; });
However, there are several caveats here, based on common but incorrect assumptions. The first one is that not every proper name follows the "first letter uppercase, all other letters lowercase" rule, and this includes many US city names. For instance, this won't work correctly with a city such as McKinney, TX. It also won't work with military addresses, which don't have a city name. It might not work correctly with non-US addresses at all. Etc. etc. This is one of the reasons why the USPS standardizes all addresses with all caps.
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
Old September 13th, 2016, 09:48 AM
This message has been deleted by step.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 03:35 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.