SoFunction
Updated on 2025-04-04

Automatically filter the input value of the input box and replace the punctuation operation in special characters.

I won't say much nonsense, let's just read the code~

<Input v-model="relatedWords" type="textarea" placeholder="Please enter" @input='verifyInput()'/>

verifyInput(v){
  let _this=this;
  let punctuation = /[`~!@#$%^&*_\-=<>?:"{}|.\/;'\\[\]·~!@#¥%……&——\-={}|《》?:“”【】、;‘'。、]/im;
  let arr=('')
  let str=''
  (i=>{
    if(!(i)){
     str+=i
    }
  })
  str=(/(/g,'(')
  str=(/)/g,')')
  str=(/,/g,',')
  this.$nextTick(j=>{
    =str
  })
},

Supplementary knowledge:vue el-input prohibits input of special characters Only numbers can be entered Regular verification

I won't say much nonsense, let's just read the code~

&lt;el-input
 size="small"
 v-model="city"
 placeholder="Please enter the city name"
 @blur="addCity(scope.$index)"
 @="btKeyUp"
 @="btKeyDown"
&gt;&lt;/el-input&gt;
 
// In methods 
   // Only enter Chinese characters, English, and numbers  btKeyDown(e) {
     = (/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g,"");
  },
  //Restrict input of special characters  btKeyUp(e) {
     = (/[`~!@#$%^&amp;*()_\-+=&lt;&gt;?:"{}|,.\/;'\\[\]·~!@#¥%……&amp;*()——\-+={}|《》?:“”【】、;‘',。、]/g,"");
  }

Use keyup and other events in el-input. You need to add .native. Otherwise, the event cannot be executed normally

Below is only the number you can enter

 &lt;el-input
  size="small"
  v-model=".order_number"
  v-show=".isShowInp_order"
  @blur="editOrder(scope.$index,)"
  v-focus
  @="UpNumber"
  @="UpNumber"
  class="table_input"       
&gt;&lt;/el-input&gt;  
 
// Only numbers can be entered  UpNumber(e) {
     = (/[^\d]/g,"");
  }

The above article "Automatic filtering of input values ​​in the input box" in the substitution of special characters is all the content I share with you. I hope you can give you a reference and I hope you can support me more.