js校验规则--去空格、加空格
为了更加直观,有些号码需要加空格:
// 拼接空格,每4位加一个空格 let bankAccount = '6228888888888888888'; let blank_value = bankAccount.replace(/\s/g,'').replace(/(.{4})/g,"$1 ").trim(); console.log(blank_value);
字符串去中间空格:
// 字符串去中间空格 let value = 'ab cd efg'; let temp = value.replace(/[ ]/g, ""); console.log(temp);
字符串去首尾空格:
let str = ' abcdefg '; let new_str = str.trim(); console.log(new_str);