// 规则名称验证规则 不包含特殊字符let checkGroupName= (rule, value, callback) => {let reg = /^[0-9A-Za-z\u4e00-\u9fa5\(\)\(\)]+$/;if (value!=='' && !reg.test(value)) {callback(new Error("请填写正确格式的规则名称"));} else {if(!checkLength(value)){callback(new Error("最大长度为 40 个字符"));}else{return callback();}}};// 中英文区分限制 字符数let checkLength=(data)=> {let REG_CHINESE = /[\u4e00-\u9fa5]/g;let REG_NOT_CHINESE =/[^\u4e00-\u9fa5]/g;let MAX = 40;if (data) {const chineseLength = data.match(REG_CHINESE) ? data.match(REG_CHINESE).length : 0;const charLength = data.match(REG_NOT_CHINESE) ? data.match(REG_NOT_CHINESE).length : 0;let total = chineseLength * 2 + charLength;return !(total > MAX);}}
如果觉得《输入框限制字节数 区分中英文》对你有帮助,请点赞、收藏,并留下你的观点哦!