您的当前位置:首页正文

js关于字符长度限制的问题示例探讨_基础知识

2020-11-27 来源:个人技术集锦

代码如下:
var fun = function(str){
var preg = new RegExp("[\u4e00-\u9fa5]+","gi");
var preg2 = new RegExp("[^\u4e00-\u9fa5]","gi");
var count = 0;
for(var i=0;iif(preg.test(str[i])){
count = count+2;
}else{
count = count+1;
}
}
return count;
}
Top