Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

capitalize first charcter sentence

New Here ,
May 05, 2017 May 05, 2017

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

TOPICS
Acrobat SDK and JavaScript , Windows
982
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 09, 2017 May 09, 2017

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

...
Translate
Community Expert ,
May 05, 2017 May 05, 2017

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 05, 2017 May 05, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 05, 2017 May 05, 2017

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 06, 2017 May 06, 2017

Joel,

Lets fix it before they commit.  I just know there will be cutting and pasting by someone.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2017 May 09, 2017

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(". ");
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 09, 2017 May 09, 2017
LATEST

Thanks Joel, I will give this a try when I get into the office

Connie

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines