Word Counter in javascript
Before writing this post,when i have searched for the word counter in javascript i found so many scripts that are not up to the mark.The script was like below. function countwords(textarea){ var words=textarea.split(" "); alert(words.length+" words"); } This script is wrong.You are having question why its wrong?.Because splitting with space is used in the above script.Its not the only thing to separate the words. A newline will be inserted if there is Return at the end of the word, which won't be counted as a word separator by the above code.commas or other punctuations which are not followed by a space are also not handled in the above script.Even if you leave a space at the end of the word it will also counted as a word that is totally wrong. So what could be the right solution for this case? As a solution, in the following script we are using regular expression.The pattern '\w+'used here will match a srting of characters of the word.Using this scri...