问题描述:前端提交form表单要求el-input/el-input-number,不能输入 @#¥%……&*……
分析问题:在事件或者方法中把字符串替代成空
解决问题:
1)
在mian.js中添加【vue原型上添加方法,便于全局使用】
Vue.prototype.validForbid = function (value, number = 255) {
value = value.replace(/[`~!@#$%^&*()_\-+=<>?:"{}|,./;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘’,。、]/g, '').replace(/\s/g, "");
if (value.length >= number) {
this.$message({
type: "warning",
message: `输入内容不能超过${number}个字符`
});
}
return value;
}
2)
在html中加上@input触发的方法
<el-input
:value="form.name"
@input="e => form.name = validSe(e)"
maxlength="10"
placeholder="过滤特殊字符长度10"
></el-input>