// 非法字符校验
<template>
  <el-input v-bind="$attrs" v-on="currentListeners"></el-input>
</template>
<script>
export default {
  computed: {
    currentListeners () {
      let _this = this
      return Object.assign({}, this.$listeners, {
        input: function (val) {
          _this.setVal(val)
        }
      })
    }
  },
  methods: {
    setVal (val) {
      // 非法字符
      let isReg = /^[\s\u4e00-\u9fa5a-z0-9_-]{0,}$/.test(val.toLowerCase())
      // 去除前后空格
      let isCn = val.replace(/(^\s*)|(\s*$)/g, '')
      if (isReg) {
        this.$emit('input', isCn)
      }
    }
  }
}
</script>
