VUE 项目 去除 input 框值 所有空格、vue 组件去除空格、input 去除空格 vue input 清除空格和换行

1.以下所有方法 我都试过:不行。

str.trim(); //去掉首尾空格
str.replace(" ",""); //去除所有空格,包括首尾、中间
str.replaceAll(" ", ""); //去掉所有空格,包括首尾、中间
str.replaceAll(" +","");  //去掉所有空格,包括首尾、中间
str.replaceAll("\\s*", ""); //可以替换大部分空白字符, 不限于空格 ;

2. 改用正则:

str.replace(/\s*/g,"")

运行成功,特别记录下下。

2019.5.9 补充:

str.replace(/\ +/g, "");    // 去除 空格
str.replace(/[\r\n]/g, "");    // 去除 换行符
str.trim(); // 去除 前后空格

 

nameInput(){
    //不允许输入换行
    this.invoice.name = this.invoice.name.replace(/[\r\n]/g, '');
},
handleInput(){
    //只允许输入数字和字母
    this.invoice.code = this.invoice.code.replace(/[^A-Za-z0-9]/g, '').toUpperCase();
    console.log(this.invoice.code)
}
//去掉空格和换行符
this.invoice.title = this.invoice.title.replace(/\s*/g,'');

 

 

https://cloud.tencent.com/developer/article/1980008?areaSource=102001.6&traceId=wQdSoDXmDDKWAj5g2_TsP
posted @ 2023-12-26 09:44  Shimily  阅读(1297)  评论(0)    收藏  举报