再一次開發中碰到一個問題,為了防止交易雙方在備注中互留電話導致詐騙的發生,做了一個自動將備注中的數字替換為*的需求
話不多說,上代碼
let output = [];
let text = "123456你好123你好123"
for (let i = 0, i < text .length ; i++) {
if (text [i].match(/\d/)) {
output.push('*');
} else {
output.push(text [i]);
}
}
text = output.join('')
//輸出******你好***你好***