elementui的el-input校验
1、输入框中只能输入中文
rules: { title: [ { required: true, message: "请输入中文的标题", trigger: "blur" }, { validator: function(rule, value, callback) { //校验中文的正则:/^[\u4e00-\u9fa5]{0,}$/ if (/^[\u4e00-\u9fa5]+$/.test(value) == false) { callback(new Error("请输入中文")); } else { //校验通过 callback(); } }, trigger: "blur" } ], }
2、输入框中只能输入英文
rule:[ subsysShow: [ { required: true, message: "请输入英文的组件名", trigger: "blur" }, { validator: function(rule, value, callback) { // 校验英文的正则 if (/[a-zA-z]$/.test(value) == false) { callback(new Error("请输入英文")); } else { //校验通过 callback(); } }, trigger: "blur" } ], ]