I am currently using the following Javascript for Title Case, but I would like to include exceptions (i.e. last names starting with Mc, force uppercase of State abbreviations, and abbreviations for North East - NE, etc.).
---Beginning of JavaScript - Entered at Document Level---
function UpperCase(sString) {
return sString.toUpperCase();}
function LowerCase(sString) {
return sString.toLowerCase();}
function FirstUpperCase(sInput) {
var aInput = sInput.split(" "); // make an array split at space
var sCharacter = '';
var sWord='';
// for each element of word array, capitalize the first letter
for(i = 0; i
---Beginning Script Added to Field's Custom Keystroke Script---
event.value = event.value.toLowerCase().replace(/\b\w/g, function(match){return match.toUpperCase();});
---End of Keystroke Script---
For example, I enter the following:
john mcelroy
123 any street ne
anywhere, ca 92130
Which is converted to:
John Mcelroy
123 Any Street Ne
Anywhere, Ca 92130
...but it needs to be the following:
John McElroy
123 Any Street NE
Anywhere, CA 92130
Any suggestions would be greatly appreciated.
I would completely separate the different steps. Start with your generic TitleCase script, and then create another method (or methods) that looks for special cases.
For example, this method will convert any two-letter word to upper-case:
function specialCaseStateCode(str) {
if (/^[a-zA-Z]{2}$/.test(str))
str = str.toUpperCase();
return str;
}
- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com