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

Capitalize first letter of Every Sentence in Textfield

Explorer ,
Mar 23, 2024 Mar 23, 2024

Copy link to clipboard

Copied

Hello All,

I am looking for a way to capitalize the first letter of each sentence within a textfield of a custom form in Acrobat. This can be done once the user finishes entering their entry. I do not want any other text changed except the first letter, of every sentence separated by a period and a space. Any help is appreciated. Thank you!

TOPICS
Create PDFs , JavaScript , Modern Acrobat , PDF , PDF forms

Views

201

Translate

Translate

Report

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 2 Correct answers

Community Expert , Mar 24, 2024 Mar 24, 2024

Use this as 'Validate' or On Blur script:

var text = event.value;
var sentences = text.split(". ");
for (var i=0; i<sentences.length; i++) {
sentences[i] = sentences[i].charAt(0).toUpperCase() + sentences[i].slice(1);}
var newText = sentences.join(". ");
event.value = newText;

Votes

Translate

Translate
Community Expert , Mar 24, 2024 Mar 24, 2024

Try this. It's much simpler.

 

event.value = event.value.replace(/\b[^\.]*/gm, ((a)=>a.replace(/\w/,(b=>b.toUpperCase()))));

 

Votes

Translate

Translate
Community Expert ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

Use this as 'Validate' or On Blur script:

var text = event.value;
var sentences = text.split(". ");
for (var i=0; i<sentences.length; i++) {
sentences[i] = sentences[i].charAt(0).toUpperCase() + sentences[i].slice(1);}
var newText = sentences.join(". ");
event.value = newText;

Votes

Translate

Translate

Report

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
Explorer ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

Thank you this worked!

Votes

Translate

Translate

Report

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 ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

Is it a multi-line field? Should happen if the user presses Enter without a period at the end of the sentence? Or if the sentence ends with a question mark, or an exclamation point?

Votes

Translate

Translate

Report

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
Explorer ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

Yes multi-line text box. Multiple senetences. Data is entered in paragraph form. Basically looks for when they click to the next field, the magic happens. There should not be any question marks or exclamation points in this field however we can include, if easy.

Votes

Translate

Translate

Report

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 ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

Then use the code provided above.

Votes

Translate

Translate

Report

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 ,
Mar 24, 2024 Mar 24, 2024

Copy link to clipboard

Copied

Try this. It's much simpler.

 

event.value = event.value.replace(/\b[^\.]*/gm, ((a)=>a.replace(/\w/,(b=>b.toUpperCase()))));

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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
Explorer ,
Mar 25, 2024 Mar 25, 2024

Copy link to clipboard

Copied

LATEST

Thank you!! It also worked. 

Votes

Translate

Translate

Report

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