Sometimes it is necessary to determine whether a character is a Chinese character. For example, when the user inputs content containing Chinese and English, it needs to be used to determine whether it exceeds the specified length. There are usually two ways to judge using Javascript.
1. Use regular expressions to determine
js determines whether the character is a Chinese character < ;/body>
2. Use Unicode character range to determine
The following method is used to count the length of the input string. If it is a Chinese character, the string length is increased by 2; otherwise, the string length is increased by 1.
function chkstrlen(str)
{
var strlen = 0;
for(var i = 0;i < str.length; i )
{
if(str.charCodeAt(i) > 255) //If it is a Chinese character, then String length plus 2
strlen = 2;
else