const validateName10 = (rule, value, callback) => {
var len = 0;
for (var i = 0; i < value.length; i++) {
var c = value.charCodeAt(i);
if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
len++; //英文字符长度
} else {
len += 2; //中文字符长度
}
}
if (len == '') {
callback(new Error('不能为空'));
} else if (len > 20) {
callback(new Error('不能超过10个字'));
} else {
// console.log(value.length)
callback();
}
};
rules: {
signBtnCopy: [
[{required: true}, {validator: validateName10, trigger: 'blur' }],
],
},
<el-form-item label="签到按钮文案:" prop="signBtnCopy">
<el-input v-model="ruleForm.signBtnCopy" placeholder="请输入"></el-input>
<span class="hint g-l-complex-i">不超过10字符,英文和数字等于0.5字符</span>
</el-form-item>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…