vue.js 입력 상자 입력 값 자동 필터 특수 문자 대체 문장부호 작업

나는 쓸데없는 말을 더 이상 하지 않겠다. 모두들 코드를 직접 보는 것이 좋겠다.

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
  })
},
보충 지식: vue el-input 특수 문자 입력 금지 숫자 정규 검증만 입력 가능
나는 쓸데없는 말을 더 이상 하지 않겠다. 모두들 코드를 직접 보는 것이 좋겠다.

<el-input
 size="small"
 v-model="city"
 placeholder=" "
 @blur="addCity(scope.$index)"
 @keyup.native="btKeyUp"
 @keydown.native="btKeyDown"
></el-input>
 
// methods  
 
   //  、 、 
  btKeyDown(e) {
    e.target.value = e.target.value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5]/g,"");
  },
  // 
  btKeyUp(e) {
    e.target.value = e.target.value.replace(/[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]・~!@#¥%……&*()――\-+={}|《》?:“”【】、;‘',。、]/g,"");
  }
el-input에서 keyup 등 이벤트를 사용하려면 추가해야 합니다.native 그렇지 않으면 이벤트를 정상적으로 실행할 수 없습니다.
다음은 숫자만 입력할 수 있습니다.

 <el-input
  size="small"
  v-model="scope.row.order_number"
  v-show="scope.row.isShowInp_order"
  @blur="editOrder(scope.$index,scope.row)"
  v-focus
  @keyup.native="UpNumber"
  @keydown.native="UpNumber"
  class="table_input"       
></el-input>  
 
//   
  UpNumber(e) {
    e.target.value = e.target.value.replace(/[^\d]/g,"");
  }
이상js 입력 상자 입력 값 자동 필터 특수 문자 교체 중 문장부호 조작은 편집자가 모두에게 공유한 모든 내용입니다. 참고 부탁드리고 저희를 많이 사랑해 주십시오.

좋은 웹페이지 즐겨찾기