VUE+ElementUI 校验表单的输入框是否含有特殊字符
data() {let validateInput = (rule, value, callback) => {if (!this.checkSpecialKey(value)) {callback(new Error("不能含有特殊字符!!"));} else {callback();...
·
data() {
let validateInput = (rule, value, callback) => {
if (!this.checkSpecialKey(value)) {
callback(new Error("不能含有特殊字符!!"));
} else {
callback();
}
};
return {
form: {
inputText: ""
},
rules: {
famc: [
{required: true, message: '请输入方案名称', trigger: 'blur'},
{ validator: validateInput, trigger: 'blur' }
]
}
}
}
methods: {
checkSpecialKey(str) {
let specialKey = "[`~!#$^&*()=|{}':;'\\[\\].<>/?~!#¥……&*()——|{}【】‘;:”“'。,、?]‘'";
for (let i = 0; i < str.length; i++) {
if (specialKey.indexOf(str.substr(i, 1)) != -1) {
return false;
}
}
return true;
},
}
更多推荐
已为社区贡献17条内容
所有评论(0)