Kỹ thuật đơn giản: che một phần local-part (phần trước @) bằng dấu ba chấm ... để bot thu thập email khó nhận diện, nhưng người dùng vẫn nhận ra.
Thuật toán
- Tách chuỗi tại
@→[local, domain]. - Giữ lại nửa đầu local-part (hoặc tỷ lệ tùy chọn).
- Ghép:
local_ngắn + '...@' + domain.
Code
<script>
function anEmail(email) {
const [local, domain] = email.split('@');
if (!domain) return email; // Không có @
const keep = Math.ceil(local.length / 2); // Giữ nửa đầu
return local.slice(0, keep) + '...@' + domain;
}
document.write(anEmail('batman@gmail.com')); // bat...@gmail.com
document.write('<br>');
document.write(anEmail('john.doe@company.co.uk')); // john...@company.co.uk
</script>
Kết quả
bat...@gmail.com john...@company.co.uk
Cải tiến: Giữ ký tự đầu và cuối
function anEmailBetter(email) {
const [local, domain] = email.split('@');
if (!domain || local.length <= 2) return email;
return local[0] + '...' + local.slice(-1) + '@' + domain;
}
// batman@gmail.com → b...n@gmail.com
Lưu ý bảo mật
- Chỉ che mắt người — bot hiện đại vẫn có thể giải mã pattern này.
- Bảo vệ thực sự: không public email thuần text; dùng form liên hệ, reCAPTCHA, hoặc mã hóa JS phức tạp hơn.
- Side-channel: email trong
mailto:link vẫn bị thu thập.