Home > Article > Web Front-end > Example of using regular expressions to calculate the length of Chinese characters in javascript_javascript skills
Since JavaScript is unicode encoded, all characters are one for it, but not for the background program. Usually, one Chinese character in the background program occupies two bytes, which leads to the front-end and back-end verification length. Inconsistency, this problem can be solved through regularization.
Sometimes, for the sake of beauty and not affecting the layout and interface, some copywriting will be truncated. However, the width of Chinese and English are different. If the Chinese is truncated according to English standards, or the English is truncated according to Chinese standards, Obviously it will be long and short, especially things like nicknames that are easy to have both Chinese and English. We can also use the above idea