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

Capitalize first letter of Every Sentence in Textfield

Explorer ,
Mar 23, 2024 Mar 23, 2024

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
786
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
2 ACCEPTED SOLUTIONS
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;

View solution in original post

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 ,
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()))));

 

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

View solution in original post

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

Thank you this worked!

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

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?

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

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.

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

Then use the code provided above.

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 ,
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()))));

 

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

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

Thank you!! It also worked. 

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