I've been looking to add a word and character count to a textarea using jQuery although all I've found are plugins to limit characters and words.
I would like to update in real-time, so that every time a user adds a character, or a word, the counter updates.
Is there a simple way to check for words and characters?
How to use an online word counter and character counter tool. 123WordCounter is incredibly easy to use and can give you realtime results. Just type or paste your text in the text box, and it will show you the word count for the number of words, characters, sentences, and paragraphs.
You can get a character count in a Word document by selecting the "Review" tab and clicking "Word Count." You can find both the number of characters with spaces and the character count not including spaces. You can add the Word Count dialog box to the Quick Access toolbar so it's always one click away.
Yes, the character count includes all spaces, punctuation and letters. Anything that moves your cursor counts as a character.
Answer: 3,000 characters is between 428 words and 750 words with spaces included in the character count.
function wordCount(val) {
var wom = val.match(/\S+/g);
return {
charactersNoSpaces: val.replace(/\s+/g, '').length,
characters: val.length,
words: wom ? wom.length : 0,
lines: val.split(/\r*\n/).length
};
}
var textarea = document.getElementById('text');
var result = document.getElementById('result');
textarea.addEventListener('input', function() {
var wc = wordCount(this.value);
result.innerHTML = (`
<br>Characters (no spaces): ${wc.charactersNoSpaces}
<br>Characters (and spaces): ${wc.characters}
<br>Words: ${wc.words}
<br>Lines: ${wc.lines}
`);
});
<textarea id="text" cols="30" rows="4"></textarea>
<div id="result"></div>
char_count = $("#myTextArea").val().length;
word_count = $("#myTextArea").val().split(" ").length;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With