JavaScript Count Words in String
var str = "your long string with many words.";
var wordCount = str.match(/(\w+)/g).length;
alert(wordCount); //6
// \w+ between one and unlimited word characters
// /g greedy - don't stop after the first match
Unsightly Unicorn