I want to make sentence case with JavaScript.
Input:
hello
world
example
I have tried this so far:
$('.sentenceCase').click(function(event) {
var rg = /(^\w{1}|\.\s*\w{1})/gi;
var textareaInput=$('.textareaInput').val();
myString = textareaInput.replace(rg, function(toReplace) {
return toReplace.toUpperCase();
});
$('.textareaInput').val(myString);
});
If I input: my name is hello. i have a pen
my output is alright. (Output: My name is hello. I have a pen
)
But for the first example, the output of my code is:
Hello
world
example
I want the output to be:
Hello
World
Example
How can I do that? (After any fullstop "." the letter will be capital letter)