vue.js 輸入框輸入值自動過濾特殊字符替換中問標點

<Input v-model="relatedWords" type="textarea" placeholder="請輸入" @input='verifyInput(formItem.relatedWords)'/>
verifyInput(v){
   let _this=this;
   let punctuation = /[`~!@#$%^&*_\-=<>?:"{}|.\/;'\\[\]·~!@#¥%……&——\-={}|《》?:“”【】、;‘’。、]/im;
   let arr=v.split('')
   let str=''
   arr.map(i=>{
       if(!punctuation.test(i)){
          str+=i
       }
    })
   str=str.replace(/(/g,'(')
   str=str.replace(/)/g,')')
   str=str.replace(/,/g,',')
   this.$nextTick(j=>{
        this.relatedWords=str
    })
},

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章