The calculation method for the number of JS words (with Word calculated as the formula)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.