Background
Users often need a certain number of words to fill in the required field restrictions, but JS is taken out by value.length often vary greatly, with the actual words. Usually the real user complains. Obviously, I did not write so many words, but the system prompted more than the word limit. Then, I learned the word rule, which is used to calculate the number of words. He wrote a number of such programs.
"Reference Code"
Use Word to calculate body Word function fngetcpmiswords (str) {slen = 0;try{//First enter newline character to do special processing str = str.replace (/(\r\n+|\s+| +)/g, "Tantrayana" );//processing English character numbers, consecutive letters, numbers, English symbols as a word str = str.replace (/[\x00-\xff]/g, "M");//merge characters M, consecutive letters, numbers, English symbols as a word str = str.replace (/ m+/g, "*"); Remove carriage return newline character str = str.replace (/Tantrayana +/g, "");//Returns the word count Slen = str.length;} catch (e) {}return slen;}
Description
The calculation of the time with a special Chinese character "Tantrayana" split, it is not surprising better, suppose there is a good way. I beg to speak.
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
The calculation method for the number of JS words (with Word calculated as the formula)