js字节长度判断
发布: 2020-02-12 19:24:06标签: js基础
字符串字节长度判断(汉字算长度为2,英文长度为1)
01function validateLen(str = '', maxLen = 10) {02 return str.replace(/[\u4e00-\u9fa5]/g,"00").length <= maxLen03}
复制代码01function validateLen(str = '', maxLen = 10) {02 return str.replace(/[\u4e00-\u9fa5]/g,"00").length <= maxLen03}
复制代码