1 Reply Latest reply on Oct 15, 2015 9:02 PM by George_Johnson

    Upper Case - Title Case - Sentence Case

    sw777 Level 1

      Hi all,


      I am having trouble understanding how Javascript defines Upper Case as opposed to Title Case.


      I have used the following script to change "john smith" to "John Smith" in one of my document's text fields...


           event.value = event.value.toLowerCase().replace(/\b\w/g, function(match){return match.toUpperCase();});


      The "match.toUpperCase()" part  seems to indicate that I am converting to Upper Case, but the result appears to be Title Case.


      Is there something in this script that forces the "match.toUpperCase()"to be applied to the first letter of each word only?


      Also, how would I modify the script to change "john smith" to "JOHN SMITH" (my understanding of Upper Case) and also "John smith" (my understanding of Sentence Case).


      Thanks in anticipation. :-)

        • 1. Re: Upper Case - Title Case - Sentence Case
          George_Johnson MVP & Adobe Community Professional

          Yes, the regular expression \b\w means a word boundary (\b) followed by a word character (\w). So the replace method that used will replace the first character of each word in the string (event.value) with that character converted to upper case. The g character at the end of the regular expression means to match globally throughout the string, so it will match the first character of all words in the string.