Copy link to clipboard
Copied
how would you force capitalization of the first letter of the first word in each sentence in a multi line text box. all other words in the sentence should be lower case
Add the following code to the custom validation script of the field. The code will split the paragraph into sentences as long as the separator is a period followed by at least one space. It then strips and leading spaces in case people double space after a period (yuck) and then converts the first character to uppercase... it doesn't bother to check. It then reassembles the sentences into a paragraph where the sentences are separated by a period and a single space.
The conversion happens when the
...Copy link to clipboard
Copied
Do you care how many spaces come after the period or do you need to capitalize the first non-space character after a period? Also, are we assuming that the first non-space character of the field should be capitalized?
Copy link to clipboard
Copied
Thank you for answering my question.
We would want to capitalize the first character in the text then it would be the first non-space character after a period. Yes the first non-space character should be capitalized.
Copy link to clipboard
Copied
It's easy enough to correct the capitalization when the user exits the field but correcting it as they type will take a bit of work. The case where a user is just typing is pretty easy but you'd also need to consider a user pasting text into a field or inserting text into a field that's already populated.
Do you just want it fixed before they commit the field or as they type/edit the field?
Copy link to clipboard
Copied
Joel,
Lets fix it before they commit. I just know there will be cutting and pasting by someone.
Copy link to clipboard
Copied
Add the following code to the custom validation script of the field. The code will split the paragraph into sentences as long as the separator is a period followed by at least one space. It then strips and leading spaces in case people double space after a period (yuck) and then converts the first character to uppercase... it doesn't bother to check. It then reassembles the sentences into a paragraph where the sentences are separated by a period and a single space.
The conversion happens when the user exits the field just prior to committing the value.
var para = event.value;
var sentences = para.split(". ");
for (var i=0; i < sentences.length; i++) {
sentences = sentences.trim().charAt(0).toUpperCase() + sentences.slice(1);
}
event.rc = true;
event.value = sentences.join(". ");
Copy link to clipboard
Copied
Thanks Joel, I will give this a try when I get into the office
Connie
Find more inspiration, events, and resources on the new Adobe Community
Explore Now