标签:校验 for 对象 obj parent 方法 set rac 补充
checkLimitCharacterLength(itemName, length, parentObj) { //校验字符长度(变量名,限制字符数,变量所属的对象)
if (!parentObj) {
parentObj = this;
}
let value = parentObj[itemName];
let valueArray = value.split(‘‘);
let _len = 0
for (let i = 0, len = value.length; i < len; i++) {
if(_len < length) {
if(/[0-9a-zA-Z,\.\!@#$%^&\*\(\):";‘\/`~\-=_\+]/.test(valueArray[i])) {
_len += 1
}
else {
_len += 2
}
}
else {
setTimeout(() => {
parentObj[itemName] = value.substring(0, i);
}, 0)
break;
}
}
}
标签:校验 for 对象 obj parent 方法 set rac 补充
原文地址:https://www.cnblogs.com/shoryee/p/9774675.html