capitalize first charcter sentence
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
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 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(". ");
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.