Skip to main content
Participating Frequently
March 24, 2024
Answered

Capitalize first letter of Every Sentence in Textfield

  • March 24, 2024
  • 2 replies
  • 1035 views

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!

This topic has been closed for replies.
Correct answer Thom Parker

Try this. It's much simpler.

 

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

 

2 replies

try67
Community Expert
Community Expert
March 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?

jmcramboAuthor
Participating Frequently
March 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.

try67
Community Expert
Community Expert
March 24, 2024

Then use the code provided above.

Nesa Nurani
Community Expert
Community Expert
March 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;
jmcramboAuthor
Participating Frequently
March 24, 2024

Thank you this worked!